Fixed StaticResizeTrait::resize() bad image height/width attributes if null values are passed to the method

This commit is contained in:
Matias Griese
2020-12-11 11:25:37 +02:00
parent d3e9083869
commit ba23cceae7
3 changed files with 14 additions and 16 deletions

View File

@@ -16,6 +16,7 @@
* Fixed unimplemented `PageObject::getOriginal()` call [#3098](https://github.com/getgrav/grav/issues/3098)
* Fixed `Argument 1 passed to Grav\Common\User\DataUser\User::filterUsername() must be of the type string` [#3101](https://github.com/getgrav/grav/issues/3101)
* Fixed broken check if php exif module is enabled in `ImageFile::fixOrientation()`
* Fixed `StaticResizeTrait::resize()` bad image height/width attributes if `null` values are passed to the method
# v1.7.0-rc.19
## 12/02/2020

View File

@@ -24,8 +24,16 @@ trait StaticResizeTrait
*/
public function resize($width = null, $height = null)
{
$this->styleAttributes['width'] = $width . 'px';
$this->styleAttributes['height'] = $height . 'px';
if ($width) {
$this->styleAttributes['width'] = $width . 'px';
} else {
unset($this->styleAttributes['width']);
}
if ($height) {
$this->styleAttributes['height'] = $height . 'px';
} else {
unset($this->styleAttributes['height']);
}
return $this;
}

View File

@@ -9,6 +9,8 @@
namespace Grav\Common\Page\Medium;
use Grav\Common\Media\Traits\StaticResizeTrait as NewResizeTrait;
user_error('Grav\Common\Page\Medium\StaticResizeTrait is deprecated since Grav 1.7, use Grav\Common\Media\Traits\StaticResizeTrait instead', E_USER_DEPRECATED);
/**
@@ -18,18 +20,5 @@ user_error('Grav\Common\Page\Medium\StaticResizeTrait is deprecated since Grav 1
*/
trait StaticResizeTrait
{
/**
* Resize media by setting attributes
*
* @param int|null $width
* @param int|null $height
* @return $this
*/
public function resize($width = null, $height = null)
{
$this->styleAttributes['width'] = $width . 'px';
$this->styleAttributes['height'] = $height . 'px';
return $this;
}
use NewResizeTrait;
}