From d8bbde74d7e0173dd0fed00276b9816d2e7566fb Mon Sep 17 00:00:00 2001 From: Ryan Cramer Date: Fri, 24 May 2019 14:22:07 -0400 Subject: [PATCH] A couple other ImageSizerEngine adjustments for webp --- wire/core/ImageSizerEngine.php | 18 +++++++++++------- wire/core/ImageSizerEngineGD.php | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/wire/core/ImageSizerEngine.php b/wire/core/ImageSizerEngine.php index be7ba089..599629e2 100755 --- a/wire/core/ImageSizerEngine.php +++ b/wire/core/ImageSizerEngine.php @@ -1657,13 +1657,17 @@ abstract class ImageSizerEngine extends WireData implements Module, Configurable return false; // fallback or failed } - // all went well, copy back the temp file, remove the temp file - if(!@copy($this->tmpFile, $this->filename)) return false; // fallback or failed - $this->wire('files')->chmod($this->filename); - $this->wire('files')->unlink($this->tmpFile); - - // post processing: IPTC, setModified and reload ImageInfo - $this->writeBackIPTC($this->filename, false); + if($this->webpOnly) { + $this->wire('files')->unlink($this->tmpFile); + } else { + // all went well, copy back the temp file, + if(!@copy($this->tmpFile, $this->filename)) return false; // fallback or failed + $this->wire('files')->chmod($this->filename); + // remove the temp file + $this->wire('files')->unlink($this->tmpFile); + // post processing: IPTC, setModified and reload ImageInfo + $this->writeBackIPTC($this->filename, false); + } $this->setModified($this->modified); $this->loadImageInfo($this->filename, true); diff --git a/wire/core/ImageSizerEngineGD.php b/wire/core/ImageSizerEngineGD.php index 45c89600..65bb9cb7 100755 --- a/wire/core/ImageSizerEngineGD.php +++ b/wire/core/ImageSizerEngineGD.php @@ -239,7 +239,7 @@ class ImageSizerEngineGD extends ImageSizerEngine { // current version is already the desired result, we only may have to compress JPEGs but leave GIF and PNG as is: - if(!$isModified && ($this->imageType == \IMAGETYPE_PNG || $this->imageType == \IMAGETYPE_GIF)) { + if(!$isModified && !$this->webpOnly && ($this->imageType == \IMAGETYPE_PNG || $this->imageType == \IMAGETYPE_GIF)) { $result = @copy($srcFilename, $dstFilename); if(isset($image) && is_resource($image)) @imagedestroy($image); // clean up if(isset($image)) $image = null;