diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e5566018..3db3209e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/system/src/Grav/Common/Media/Traits/StaticResizeTrait.php b/system/src/Grav/Common/Media/Traits/StaticResizeTrait.php index cd14779f1..4d0899ec1 100644 --- a/system/src/Grav/Common/Media/Traits/StaticResizeTrait.php +++ b/system/src/Grav/Common/Media/Traits/StaticResizeTrait.php @@ -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; } diff --git a/system/src/Grav/Common/Page/Medium/StaticResizeTrait.php b/system/src/Grav/Common/Page/Medium/StaticResizeTrait.php index 57cc61b10..575aa1d3c 100644 --- a/system/src/Grav/Common/Page/Medium/StaticResizeTrait.php +++ b/system/src/Grav/Common/Page/Medium/StaticResizeTrait.php @@ -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; }