From ffa64c86b1e29dc00dd588edaf7f4114455280e1 Mon Sep 17 00:00:00 2001 From: Cole Thorsen <959538+colethorsen@users.noreply.github.com> Date: Mon, 15 Jun 2020 09:11:56 -0400 Subject: [PATCH 1/2] Fix to ImageMagickHandler -Saving an image back to the same location with a lower quality would result in a failure attempting to copy. -Saving an image to a new spot with a lower quality would result in the image not having a new quality set. --- system/Images/Handlers/ImageMagickHandler.php | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/system/Images/Handlers/ImageMagickHandler.php b/system/Images/Handlers/ImageMagickHandler.php index 5fbd7d986103..c18a900de1ea 100644 --- a/system/Images/Handlers/ImageMagickHandler.php +++ b/system/Images/Handlers/ImageMagickHandler.php @@ -288,23 +288,34 @@ public function save(string $target = null, int $quality = 90): bool { $target = empty($target) ? $this->image() : $target; - // If no new resource has been created, then we're - // simply copy the existing one. - if (empty($this->resource)) + // If no new resource has been created, and we + // aren't adjusting the quality then we're simply + // copy the existing one. + if (empty($this->resource) && $quality == 100) { + // we're moving it to the same spot so don't do anything. + if($target === null) + { + return true; + } + $name = basename($target); $path = pathinfo($target, PATHINFO_DIRNAME); return $this->image()->copy($path, $name); } + $source = $this->image()->getPathname(); + // Copy the file through ImageMagick so that it has // a chance to convert file format. - $action = '"' . $this->resource . '" "' . $target . '"'; + $action = '"' . $source . '" "' . $target . '"'; $result = $this->process($action, $quality); - unlink($this->resource); + if(!empty($this->resource)) { + unlink($this->resource); + } return true; } From 544106e9c3b9aae1391db8a7db0bf31a2b274837 Mon Sep 17 00:00:00 2001 From: Cole Thorsen <959538+colethorsen@users.noreply.github.com> Date: Tue, 16 Jun 2020 16:44:24 -0400 Subject: [PATCH 2/2] Fix for existing resource --- system/Images/Handlers/ImageMagickHandler.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/Images/Handlers/ImageMagickHandler.php b/system/Images/Handlers/ImageMagickHandler.php index c18a900de1ea..2a21f2f7dad4 100644 --- a/system/Images/Handlers/ImageMagickHandler.php +++ b/system/Images/Handlers/ImageMagickHandler.php @@ -305,7 +305,7 @@ public function save(string $target = null, int $quality = 90): bool return $this->image()->copy($path, $name); } - $source = $this->image()->getPathname(); + $source = ! empty($this->resource) ? $this->resource : $this->image()->getPathname(); // Copy the file through ImageMagick so that it has // a chance to convert file format.