diff --git a/CHANGELOG.md b/CHANGELOG.md index f8a4bb187..084fec705 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ * Fixed `Undefined method closure::fields()` when getting avatar for user, thanks @Romarain [#2422](https://github.com/getgrav/grav/issues/2422) * Grav 1.6: Added `Flex[Class]::getFlexType()` to all flex classes to have the interface for all Flex classes * FlexObjects: Remove null values during save + * Fix issue with processed images not being updated when existing image is modified # v1.6.0-rc.4 ## 03/20/2019 diff --git a/system/src/Grav/Common/Page/Medium/ImageFile.php b/system/src/Grav/Common/Page/Medium/ImageFile.php index 33f42c205..d56c34220 100644 --- a/system/src/Grav/Common/Page/Medium/ImageFile.php +++ b/system/src/Grav/Common/Page/Medium/ImageFile.php @@ -33,13 +33,14 @@ class ImageFile extends Image /** * This is the same as the Gregwar Image class except this one fires a Grav Event on creation of new cached file * - * @param string $type the image type - * @param int $quality the quality (for JPEG) - * @param bool $actual + * @param string $type the image type + * @param int $quality the quality (for JPEG) + * @param bool $actual + * @param array $extras * * @return string */ - public function cacheFile($type = 'jpg', $quality = 80, $actual = false) + public function cacheFile($type = 'jpg', $quality = 80, $actual = false, $extras = []) { if ($type === 'guess') { $type = $this->guessType(); @@ -50,7 +51,7 @@ class ImageFile extends Image } // Computes the hash - $this->hash = $this->getHash($type, $quality); + $this->hash = $this->getHash($type, $quality, $extras); // Seo friendly image names $seofriendly = Grav::instance()['config']->get('system.images.seofriendly', false); @@ -103,4 +104,42 @@ class ImageFile extends Image return $this->getFilename($file); } + + /** + * Gets the hash. + * @param string $type + * @param int $quality + * @param [] $extras + * @return null + */ + public function getHash($type = 'guess', $quality = 80, $extras = []) + { + if (null === $this->hash) { + $this->generateHash($type, $quality, $extras); + } + + return $this->hash; + } + + /** + * Generates the hash. + * @param string $type + * @param int $quality + * @param array $extras + */ + public function generateHash($type = 'guess', $quality = 80, $extras = []) + { + $inputInfos = $this->source->getInfos(); + + $datas = array( + $inputInfos, + $this->serializeOperations(), + $type, + $quality, + $extras + ); + + $this->hash = sha1(serialize($datas)); + } + } diff --git a/system/src/Grav/Common/Page/Medium/ImageMedium.php b/system/src/Grav/Common/Page/Medium/ImageMedium.php index 9369e3658..ac292191a 100644 --- a/system/src/Grav/Common/Page/Medium/ImageMedium.php +++ b/system/src/Grav/Common/Page/Medium/ImageMedium.php @@ -619,7 +619,7 @@ class ImageMedium extends Medium $this->image->merge(ImageFile::open($overlay)); } - return $this->image->cacheFile($this->format, $this->quality); + return $this->image->cacheFile($this->format, $this->quality, false, [$this->get('width'), $this->get('height'), $this->get('modified')]); } /**