From b9b802c8ea62e94990910590cadde7c2f05f91d9 Mon Sep 17 00:00:00 2001 From: Wouter Samaey Date: Fri, 30 Jul 2021 08:42:23 +0200 Subject: [PATCH 01/19] Imagick adapter, handles color profiles better --- lib/Varien/Image/Adapter/Imagick.php | 223 +++++++++++++++++++++++++++ 1 file changed, 223 insertions(+) create mode 100644 lib/Varien/Image/Adapter/Imagick.php diff --git a/lib/Varien/Image/Adapter/Imagick.php b/lib/Varien/Image/Adapter/Imagick.php new file mode 100644 index 00000000000..33981c1dbf8 --- /dev/null +++ b/lib/Varien/Image/Adapter/Imagick.php @@ -0,0 +1,223 @@ +_imageHandler->destroy(); + } + + /** + * Opens image file. + * + * @param string $filename + */ + public function open($filename) + { + $this->_fileName = $filename; + $this->getMimeType(); + $this->_getFileAttributes(); + + $this->_imageHandler = new Imagick(); + $this->_imageHandler->readImage($filename); + } + + public function save($destination = null, $newName = null) + { + if ($destination && $newName) { + $fileName = $destination . "/" . $newName; + } elseif (isset($destination) && !isset($newName)) { + $info = pathinfo($destination); + $fileName = $destination; + $destination = $info['dirname']; + } elseif (!isset($destination) && isset($newName)) { + $fileName = $this->_fileSrcPath . "/" . $newName; + } else { + $fileName = $this->_fileSrcPath . $this->_fileSrcName; + } + + $destinationDir = (isset($destination)) ? $destination : $this->_fileSrcPath; + + if (!is_writable($destinationDir)) { + try { + $io = new Varien_Io_File(); + $io->mkdir($destination); + } catch (Exception $e) { + throw new Exception("Unable to write file into directory '{$destinationDir}'. Access forbidden."); + } + } + +// if ($this->_fileType == IMAGETYPE_JPEG) { +// $threshold = (int)Mage::getStoreConfig('catalog/product_image/progressive_threshold'); +// if ($threshold && $threshold <= (imagesx($this->_imageHandler) * imagesy($this->_imageHandler) / 1000000)) { +// imageinterlace($this->_imageHandler, 1); +// +// TODO support progressive JPG? Like this? +// $this->_imageHandler->setInterlaceScheme(); +// } +// } + + // set quality param for PNG file type + $quality = $this->quality(); + if ($quality !== null) { + if ($quality < 1) { + throw new RuntimeException('Image compression quality cannot be < 1'); + } elseif ($quality > 100) { + throw new RuntimeException('Image compression quality cannot be > 100'); + } + $this->_imageHandler->setCompressionQuality($quality); + } + $this->_imageHandler->writeImage($fileName); + } + + public function display() + { + header("Content-type: " . $this->getMimeTypeWithOutFileType()); + echo $this->_imageHandler->getImageBlob(); + } + + /** + * Change the image size + * + * @param int $frameWidth + * @param int $frameHeight + */ + public function resize($frameWidth = null, $frameHeight = null) + { + if (!$frameWidth || !$frameHeight) { + throw new RuntimeException('Invalid image dimensions.'); + } + + // calculate lacking dimension + if (!$this->_keepFrame) { + if (null === $frameWidth) { + $frameWidth = round($frameHeight * ($this->_imageSrcWidth / $this->_imageSrcHeight)); + } elseif (null === $frameHeight) { + $frameHeight = round($frameWidth * ($this->_imageSrcHeight / $this->_imageSrcWidth)); + } + } else { + if (null === $frameWidth) { + $frameWidth = $frameHeight; + } elseif (null === $frameHeight) { + $frameHeight = $frameWidth; + } + } + + // define coordinates of image inside new frame + $dstWidth = $frameWidth; + $dstHeight = $frameHeight; + if ($this->_keepAspectRatio) { + // do not make picture bigger, than it is, if required + if ($this->_constrainOnly) { + if (($frameWidth >= $this->_imageSrcWidth) && ($frameHeight >= $this->_imageSrcHeight)) { + $dstWidth = $this->_imageSrcWidth; + $dstHeight = $this->_imageSrcHeight; + } + } + // keep aspect ratio + if ($this->_imageSrcWidth / $this->_imageSrcHeight >= $frameWidth / $frameHeight) { + $dstHeight = round(($dstWidth / $this->_imageSrcWidth) * $this->_imageSrcHeight); + } else { + $dstWidth = round(($dstHeight / $this->_imageSrcHeight) * $this->_imageSrcWidth); + } + } + + $filter = \Imagick::FILTER_LANCZOS; + $this->_imageHandler->resizeImage($dstWidth, $dstHeight, $filter, 1); + + if (!$this->_keepFrame) { + $canvas = new Imagick(); + // TODO support more than just JPG? + $canvas->newImage($frameWidth, $frameHeight, 'white', 'jpg'); + } + + if (!$this->_keepFrame) { + $frameWidth = $dstWidth; + $frameHeight = $dstHeight; + + $offsetX = (int)($frameWidth / 2) - (int)($dstWidth / 2); + $offsetY = (int)($frameHeight / 2) - (int)($dstHeight / 2); + $canvas->compositeImage($this->_imageHandler, \Imagick::COMPOSITE_OVER, $offsetX, $offsetY); + $this->_imageHandler = $canvas; + } + + $this->refreshImageDimensions(); + $this->_resized = true; + } + + public function rotate($angle) + { + $this->_imageHandler->rotateImage($this->imageBackgroundColor, $angle); + $this->refreshImageDimensions(); + } + + public function watermark($watermarkImage, $positionX = 0, $positionY = 0, $watermarkImageOpacity = 30, $repeat = false) + { + throw new RuntimeException('Watermark is not supported.'); + } + + public function crop($top = 0, $left = 0, $right = 0, $bottom = 0) + { + if ($left == 0 && $top == 0 && $right == 0 && $bottom == 0) { + return; + } + + $newWidth = $this->_imageSrcWidth - $left - $right; + $newHeight = $this->_imageSrcHeight - $top - $bottom; + + $this->_imageHandler->cropImage($newWidth, $newHeight, $left, $top); + $this->refreshImageDimensions(); + } + + public function checkDependencies() + { + foreach ($this->_requiredExtensions as $value) { + if (!extension_loaded($value)) { + throw new Exception("Required PHP extension '{$value}' was not loaded."); + } + } + } + + private function refreshImageDimensions() + { + $this->_imageSrcWidth = $this->_imageHandler->getImageWidth(); + $this->_imageSrcHeight = $this->_imageHandler->getImageHeight(); + } + + /** + * Gives real mime-type with not considering file type field + * + * @return string + */ + public function getMimeTypeWithOutFileType() + { + return $this->_fileMimeType; + } +} From 7efabc6580f0223cf5c5bc22b4b27cf47f0e2df2 Mon Sep 17 00:00:00 2001 From: Wouter Samaey Date: Fri, 30 Jul 2021 08:55:05 +0200 Subject: [PATCH 02/19] Update Imagick.php --- lib/Varien/Image/Adapter/Imagick.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Varien/Image/Adapter/Imagick.php b/lib/Varien/Image/Adapter/Imagick.php index 33981c1dbf8..f202744325f 100644 --- a/lib/Varien/Image/Adapter/Imagick.php +++ b/lib/Varien/Image/Adapter/Imagick.php @@ -111,7 +111,7 @@ public function display() */ public function resize($frameWidth = null, $frameHeight = null) { - if (!$frameWidth || !$frameHeight) { + if (!$frameWidth && !$frameHeight) { throw new RuntimeException('Invalid image dimensions.'); } From 0e6103a4fd7bd963e9581c50e9dd5d5cd8828c67 Mon Sep 17 00:00:00 2001 From: Wouter Samaey Date: Fri, 30 Jul 2021 08:57:32 +0200 Subject: [PATCH 03/19] Update Imagick.php --- lib/Varien/Image/Adapter/Imagick.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Varien/Image/Adapter/Imagick.php b/lib/Varien/Image/Adapter/Imagick.php index f202744325f..7843bf19582 100644 --- a/lib/Varien/Image/Adapter/Imagick.php +++ b/lib/Varien/Image/Adapter/Imagick.php @@ -143,9 +143,9 @@ public function resize($frameWidth = null, $frameHeight = null) } // keep aspect ratio if ($this->_imageSrcWidth / $this->_imageSrcHeight >= $frameWidth / $frameHeight) { - $dstHeight = round(($dstWidth / $this->_imageSrcWidth) * $this->_imageSrcHeight); + $dstHeight = (int) round(($dstWidth / $this->_imageSrcWidth) * $this->_imageSrcHeight); } else { - $dstWidth = round(($dstHeight / $this->_imageSrcHeight) * $this->_imageSrcWidth); + $dstWidth = (int) round(($dstHeight / $this->_imageSrcHeight) * $this->_imageSrcWidth); } } From 1471a610ca584c1b530cc92bcd136111d7271d0e Mon Sep 17 00:00:00 2001 From: Wouter Samaey Date: Fri, 30 Jul 2021 09:13:02 +0200 Subject: [PATCH 04/19] Update Imagick.php --- lib/Varien/Image/Adapter/Imagick.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/Varien/Image/Adapter/Imagick.php b/lib/Varien/Image/Adapter/Imagick.php index 7843bf19582..40edbb3ba9f 100644 --- a/lib/Varien/Image/Adapter/Imagick.php +++ b/lib/Varien/Image/Adapter/Imagick.php @@ -143,12 +143,15 @@ public function resize($frameWidth = null, $frameHeight = null) } // keep aspect ratio if ($this->_imageSrcWidth / $this->_imageSrcHeight >= $frameWidth / $frameHeight) { - $dstHeight = (int) round(($dstWidth / $this->_imageSrcWidth) * $this->_imageSrcHeight); + $dstHeight = ($dstWidth / $this->_imageSrcWidth) * $this->_imageSrcHeight; } else { - $dstWidth = (int) round(($dstHeight / $this->_imageSrcHeight) * $this->_imageSrcWidth); + $dstWidth = ($dstHeight / $this->_imageSrcHeight) * $this->_imageSrcWidth; } } + $dstWidth = (int) round($dstWidth); + $dstHeight = (int) round($dstHeight); + $filter = \Imagick::FILTER_LANCZOS; $this->_imageHandler->resizeImage($dstWidth, $dstHeight, $filter, 1); From 9a00be9c89e2e4e0762788ccf3db70a37ed1465d Mon Sep 17 00:00:00 2001 From: Wouter Samaey Date: Fri, 30 Jul 2021 09:38:11 +0200 Subject: [PATCH 05/19] Update Adapter.php --- lib/Varien/Image/Adapter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Varien/Image/Adapter.php b/lib/Varien/Image/Adapter.php index 65632d004b3..71ccf9febae 100644 --- a/lib/Varien/Image/Adapter.php +++ b/lib/Varien/Image/Adapter.php @@ -44,7 +44,7 @@ public static function factory($adapter) break; case self::ADAPTER_IM: - return new Varien_Image_Adapter_Imagemagic(); + return new Varien_Image_Adapter_Imagick(); break; case self::ADAPTER_IME: From fd513ee33de8d4cf22b2d9188d95b0bce8ac2a11 Mon Sep 17 00:00:00 2001 From: Wouter Samaey Date: Fri, 30 Jul 2021 13:33:37 +0200 Subject: [PATCH 06/19] Update Imagick.php --- lib/Varien/Image/Adapter/Imagick.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/Varien/Image/Adapter/Imagick.php b/lib/Varien/Image/Adapter/Imagick.php index 40edbb3ba9f..f8ed126c2af 100644 --- a/lib/Varien/Image/Adapter/Imagick.php +++ b/lib/Varien/Image/Adapter/Imagick.php @@ -31,7 +31,9 @@ public function __construct() */ public function destruct() { - $this->_imageHandler->destroy(); + if($this->_imageHandler) { + $this->_imageHandler->destroy(); + } } /** From c41214b9c4a86031da24daf8b9e7220533a7cdd1 Mon Sep 17 00:00:00 2001 From: Wouter Samaey Date: Fri, 30 Jul 2021 15:23:15 +0200 Subject: [PATCH 07/19] Added support for "exif:Orientation" --- lib/Varien/Image/Adapter/Imagick.php | 66 ++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 18 deletions(-) diff --git a/lib/Varien/Image/Adapter/Imagick.php b/lib/Varien/Image/Adapter/Imagick.php index f8ed126c2af..2c47a6eb777 100644 --- a/lib/Varien/Image/Adapter/Imagick.php +++ b/lib/Varien/Image/Adapter/Imagick.php @@ -1,7 +1,7 @@ _imageHandler) { + if ($this->_imageHandler) { $this->_imageHandler->destroy(); } } @@ -40,6 +40,8 @@ public function destruct() * Opens image file. * * @param string $filename + * @throws ImagickException + * @throws Mage_Core_Exception */ public function open($filename) { @@ -49,6 +51,26 @@ public function open($filename) $this->_imageHandler = new Imagick(); $this->_imageHandler->readImage($filename); + + $orientation = $this->_imageHandler->getImageProperty('exif:Orientation'); + if (!empty($orientation)) { + switch ($orientation) { + case 3: + $this->_imageHandler->rotateImage('#000000', 180); + break; + + case 6: + $this->_imageHandler->rotateImage('#000000', 90); + break; + + case 8: + $this->_imageHandler->rotateImage('#000000', -90); + break; + default: + Mage::throwException('Unsupported EXIF orientation: ' . $orientation); + } + } + $this->refreshImageDimensions(); } public function save($destination = null, $newName = null) @@ -118,23 +140,24 @@ public function resize($frameWidth = null, $frameHeight = null) } // calculate lacking dimension - if (!$this->_keepFrame) { + if ($this->_keepFrame) { if (null === $frameWidth) { - $frameWidth = round($frameHeight * ($this->_imageSrcWidth / $this->_imageSrcHeight)); + $frameWidth = $frameHeight; } elseif (null === $frameHeight) { - $frameHeight = round($frameWidth * ($this->_imageSrcHeight / $this->_imageSrcWidth)); + $frameHeight = $frameWidth; } } else { if (null === $frameWidth) { - $frameWidth = $frameHeight; + $frameWidth = round($frameHeight * ($this->_imageSrcWidth / $this->_imageSrcHeight)); } elseif (null === $frameHeight) { - $frameHeight = $frameWidth; + $frameHeight = round($frameWidth * ($this->_imageSrcHeight / $this->_imageSrcWidth)); } } // define coordinates of image inside new frame $dstWidth = $frameWidth; $dstHeight = $frameHeight; + if ($this->_keepAspectRatio) { // do not make picture bigger, than it is, if required if ($this->_constrainOnly) { @@ -147,30 +170,37 @@ public function resize($frameWidth = null, $frameHeight = null) if ($this->_imageSrcWidth / $this->_imageSrcHeight >= $frameWidth / $frameHeight) { $dstHeight = ($dstWidth / $this->_imageSrcWidth) * $this->_imageSrcHeight; } else { - $dstWidth = ($dstHeight / $this->_imageSrcHeight) * $this->_imageSrcWidth; + $dstWidth = ($dstHeight / $this->_imageSrcHeight) * $this->_imageSrcWidth; } } - $dstWidth = (int) round($dstWidth); - $dstHeight = (int) round($dstHeight); - + $dstWidth = (int)round($dstWidth); + $dstHeight = (int)round($dstHeight); + $frameWidth = (int)round($frameWidth); + $frameHeight = (int)round($frameHeight); + + $filter = \Imagick::FILTER_LANCZOS; $this->_imageHandler->resizeImage($dstWidth, $dstHeight, $filter, 1); - if (!$this->_keepFrame) { + if ($this->_keepFrame) { + // Add borders top+bottom or left+right $canvas = new Imagick(); // TODO support more than just JPG? $canvas->newImage($frameWidth, $frameHeight, 'white', 'jpg'); - } - if (!$this->_keepFrame) { - $frameWidth = $dstWidth; - $frameHeight = $dstHeight; +// $frameWidth = $dstWidth; +// $frameHeight = $dstHeight; - $offsetX = (int)($frameWidth / 2) - (int)($dstWidth / 2); - $offsetY = (int)($frameHeight / 2) - (int)($dstHeight / 2); + $offsetX = (int)round(($frameWidth - $dstWidth) / 2); + $offsetY = (int)round(($frameHeight - $dstHeight) / 2); $canvas->compositeImage($this->_imageHandler, \Imagick::COMPOSITE_OVER, $offsetX, $offsetY); $this->_imageHandler = $canvas; + + + } else { + // TODO is this correct? + // Do nothing? } $this->refreshImageDimensions(); From c1c09d84e2673217d5b669019c571319fe618bd6 Mon Sep 17 00:00:00 2001 From: Wouter Samaey Date: Fri, 30 Jul 2021 15:27:08 +0200 Subject: [PATCH 08/19] Update Imagick.php --- lib/Varien/Image/Adapter/Imagick.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/Varien/Image/Adapter/Imagick.php b/lib/Varien/Image/Adapter/Imagick.php index 2c47a6eb777..05dc8835181 100644 --- a/lib/Varien/Image/Adapter/Imagick.php +++ b/lib/Varien/Image/Adapter/Imagick.php @@ -196,11 +196,6 @@ public function resize($frameWidth = null, $frameHeight = null) $offsetY = (int)round(($frameHeight - $dstHeight) / 2); $canvas->compositeImage($this->_imageHandler, \Imagick::COMPOSITE_OVER, $offsetX, $offsetY); $this->_imageHandler = $canvas; - - - } else { - // TODO is this correct? - // Do nothing? } $this->refreshImageDimensions(); From ebf56264d948601a1bb104c60a57c5f94966ce97 Mon Sep 17 00:00:00 2001 From: Wouter Samaey Date: Fri, 30 Jul 2021 15:27:22 +0200 Subject: [PATCH 09/19] Update Imagick.php --- lib/Varien/Image/Adapter/Imagick.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/Varien/Image/Adapter/Imagick.php b/lib/Varien/Image/Adapter/Imagick.php index 05dc8835181..6c1b63d1f0d 100644 --- a/lib/Varien/Image/Adapter/Imagick.php +++ b/lib/Varien/Image/Adapter/Imagick.php @@ -188,10 +188,6 @@ public function resize($frameWidth = null, $frameHeight = null) $canvas = new Imagick(); // TODO support more than just JPG? $canvas->newImage($frameWidth, $frameHeight, 'white', 'jpg'); - -// $frameWidth = $dstWidth; -// $frameHeight = $dstHeight; - $offsetX = (int)round(($frameWidth - $dstWidth) / 2); $offsetY = (int)round(($frameHeight - $dstHeight) / 2); $canvas->compositeImage($this->_imageHandler, \Imagick::COMPOSITE_OVER, $offsetX, $offsetY); From 309f4ae6092472d2e808b18c2825672e794cf21a Mon Sep 17 00:00:00 2001 From: Wouter Samaey Date: Fri, 30 Jul 2021 16:11:48 +0200 Subject: [PATCH 10/19] Update Imagick.php --- lib/Varien/Image/Adapter/Imagick.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/Varien/Image/Adapter/Imagick.php b/lib/Varien/Image/Adapter/Imagick.php index 6c1b63d1f0d..cb911c510e4 100644 --- a/lib/Varien/Image/Adapter/Imagick.php +++ b/lib/Varien/Image/Adapter/Imagick.php @@ -55,6 +55,9 @@ public function open($filename) $orientation = $this->_imageHandler->getImageProperty('exif:Orientation'); if (!empty($orientation)) { switch ($orientation) { + case 1: + // Do nothing + break; case 3: $this->_imageHandler->rotateImage('#000000', 180); break; From 536046b25b2f2b9b86833dfcb9f31da595e51572 Mon Sep 17 00:00:00 2001 From: Colin Mollenhour Date: Wed, 3 Aug 2022 09:14:51 -0700 Subject: [PATCH 11/19] Update lib/Varien/Image/Adapter/Imagick.php --- lib/Varien/Image/Adapter/Imagick.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Varien/Image/Adapter/Imagick.php b/lib/Varien/Image/Adapter/Imagick.php index cb911c510e4..0a6315f1da4 100644 --- a/lib/Varien/Image/Adapter/Imagick.php +++ b/lib/Varien/Image/Adapter/Imagick.php @@ -1,7 +1,7 @@ Date: Tue, 28 Mar 2023 14:05:57 +0100 Subject: [PATCH 12/19] removed empty lines --- lib/Varien/Image/Adapter/Imagick.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/Varien/Image/Adapter/Imagick.php b/lib/Varien/Image/Adapter/Imagick.php index 0a6315f1da4..b7fe78e1a14 100644 --- a/lib/Varien/Image/Adapter/Imagick.php +++ b/lib/Varien/Image/Adapter/Imagick.php @@ -61,11 +61,9 @@ public function open($filename) case 3: $this->_imageHandler->rotateImage('#000000', 180); break; - case 6: $this->_imageHandler->rotateImage('#000000', 90); break; - case 8: $this->_imageHandler->rotateImage('#000000', -90); break; From 0404edfd361c51bfe5931c8644ba118ae6cc4f4f Mon Sep 17 00:00:00 2001 From: Fabrizio Balliano Date: Thu, 11 May 2023 17:07:31 +0100 Subject: [PATCH 13/19] removed strict types Co-authored-by: Colin Mollenhour --- lib/Varien/Image/Adapter/Imagick.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Varien/Image/Adapter/Imagick.php b/lib/Varien/Image/Adapter/Imagick.php index b7fe78e1a14..eb0bacbc456 100644 --- a/lib/Varien/Image/Adapter/Imagick.php +++ b/lib/Varien/Image/Adapter/Imagick.php @@ -1,5 +1,4 @@ Date: Thu, 11 May 2023 17:10:45 +0100 Subject: [PATCH 14/19] Update lib/Varien/Image/Adapter/Imagick.php --- lib/Varien/Image/Adapter/Imagick.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/Varien/Image/Adapter/Imagick.php b/lib/Varien/Image/Adapter/Imagick.php index eb0bacbc456..45405417ccf 100644 --- a/lib/Varien/Image/Adapter/Imagick.php +++ b/lib/Varien/Image/Adapter/Imagick.php @@ -128,8 +128,6 @@ public function display() } /** - * Change the image size - * * @param int $frameWidth * @param int $frameHeight */ From 721e9c2d206ca6f460b8d4f8db307db9eb7be9cd Mon Sep 17 00:00:00 2001 From: Fabrizio Balliano Date: Thu, 11 May 2023 17:11:09 +0100 Subject: [PATCH 15/19] Update lib/Varien/Image/Adapter/Imagick.php --- lib/Varien/Image/Adapter/Imagick.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/Varien/Image/Adapter/Imagick.php b/lib/Varien/Image/Adapter/Imagick.php index 45405417ccf..925f24505df 100644 --- a/lib/Varien/Image/Adapter/Imagick.php +++ b/lib/Varien/Image/Adapter/Imagick.php @@ -121,6 +121,9 @@ public function save($destination = null, $newName = null) $this->_imageHandler->writeImage($fileName); } + /** + * @return string + */ public function display() { header("Content-type: " . $this->getMimeTypeWithOutFileType()); From a68f9de09a88114e1ceb444e1560b7e77d849f5d Mon Sep 17 00:00:00 2001 From: Fabrizio Balliano Date: Mon, 18 Sep 2023 17:17:06 +0100 Subject: [PATCH 16/19] Minor fixes --- lib/Varien/Image/Adapter/Abstract.php | 2 +- lib/Varien/Image/Adapter/Imagick.php | 28 +++++++++++++++++---------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/lib/Varien/Image/Adapter/Abstract.php b/lib/Varien/Image/Adapter/Abstract.php index 5eeb09e56aa..9ad32f693e5 100644 --- a/lib/Varien/Image/Adapter/Abstract.php +++ b/lib/Varien/Image/Adapter/Abstract.php @@ -83,7 +83,7 @@ abstract class Varien_Image_Adapter_Abstract * original image, but after resize() it's already a scaled version. * * @see Varien_Image_Adapter_Gd2::open() - * @var resource|GdImage + * @var resource|GdImage|Imagick */ protected $_imageHandler = null; diff --git a/lib/Varien/Image/Adapter/Imagick.php b/lib/Varien/Image/Adapter/Imagick.php index 925f24505df..58f3a38a8c7 100644 --- a/lib/Varien/Image/Adapter/Imagick.php +++ b/lib/Varien/Image/Adapter/Imagick.php @@ -1,4 +1,22 @@ _fileType == IMAGETYPE_JPEG) { -// $threshold = (int)Mage::getStoreConfig('catalog/product_image/progressive_threshold'); -// if ($threshold && $threshold <= (imagesx($this->_imageHandler) * imagesy($this->_imageHandler) / 1000000)) { -// imageinterlace($this->_imageHandler, 1); -// -// TODO support progressive JPG? Like this? -// $this->_imageHandler->setInterlaceScheme(); -// } -// } - // set quality param for PNG file type $quality = $this->quality(); if ($quality !== null) { From e98bd5da417ca153b3bf275210ed391f3c94960d Mon Sep 17 00:00:00 2001 From: Fabrizio Balliano Date: Mon, 18 Sep 2023 17:19:32 +0100 Subject: [PATCH 17/19] phpdoc --- lib/Varien/Image/Adapter/Gd2.php | 16 ++++------------ lib/Varien/Image/Adapter/Imagick.php | 5 +++++ 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/lib/Varien/Image/Adapter/Gd2.php b/lib/Varien/Image/Adapter/Gd2.php index 18423d22dca..a9822c3e410 100644 --- a/lib/Varien/Image/Adapter/Gd2.php +++ b/lib/Varien/Image/Adapter/Gd2.php @@ -412,20 +412,12 @@ public function resize($frameWidth = null, $frameHeight = null) $this->_resized = true; } + /** + * @param $angle float + * @return void + */ public function rotate($angle) { - /* - $isAlpha = false; - $backgroundColor = $this->_getTransparency($this->_imageHandler, $this->_fileType, $isAlpha); - list($r, $g, $b) = $this->_backgroundColor; - if ($isAlpha) { - $backgroundColor = imagecolorallocatealpha($this->_imageHandler, 0, 0, 0, 127); - } - elseif (false === $backgroundColor) { - $backgroundColor = imagecolorallocate($this->_imageHandler, $r, $g, $b); - } - $this->_imageHandler = imagerotate($this->_imageHandler, $angle, $backgroundColor); - //*/ $this->_imageHandler = imagerotate($this->_imageHandler, $angle, $this->imageBackgroundColor); $this->refreshImageDimensions(); } diff --git a/lib/Varien/Image/Adapter/Imagick.php b/lib/Varien/Image/Adapter/Imagick.php index 58f3a38a8c7..ff1bdcefb2f 100644 --- a/lib/Varien/Image/Adapter/Imagick.php +++ b/lib/Varien/Image/Adapter/Imagick.php @@ -207,6 +207,11 @@ public function resize($frameWidth = null, $frameHeight = null) $this->_resized = true; } + /** + * @param $angle float + * @return void + * @throws ImagickException + */ public function rotate($angle) { $this->_imageHandler->rotateImage($this->imageBackgroundColor, $angle); From 966932ad4d855b559fdceff5c80c98afa25a6b16 Mon Sep 17 00:00:00 2001 From: Fabrizio Balliano Date: Wed, 14 Feb 2024 14:36:51 +0000 Subject: [PATCH 18/19] copyright and phpcs --- lib/Varien/Image/Adapter/Imagick.php | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/Varien/Image/Adapter/Imagick.php b/lib/Varien/Image/Adapter/Imagick.php index ff1bdcefb2f..08a23167acf 100644 --- a/lib/Varien/Image/Adapter/Imagick.php +++ b/lib/Varien/Image/Adapter/Imagick.php @@ -6,21 +6,16 @@ * * This source file is subject to the Open Software License (OSL 3.0) * that is bundled with this package in the file LICENSE.txt. - * It is also available through the world-wide-web at this URL: - * https://opensource.org/licenses/osl-3.0.php - * If you did not receive a copy of the license and are unable to - * obtain it through the world-wide-web, please send an email - * to license@magento.com so we can send you a copy immediately. + * It is also available at https://opensource.org/license/osl-3-0-php * * @category Varien * @package Varien_Image - * @copyright Copyright (c) 2023 The OpenMage Contributors (https://www.openmage.org) + * @copyright Copyright (c) 2024 The OpenMage Contributors (https://www.openmage.org) * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ class Varien_Image_Adapter_Imagick extends Varien_Image_Adapter_Abstract { - /** * @var Imagick */ From 89663309765f519838d04795196ad8eccc630d35 Mon Sep 17 00:00:00 2001 From: Fabrizio Balliano Date: Wed, 14 Feb 2024 14:38:22 +0000 Subject: [PATCH 19/19] phpstan --- lib/Varien/Image/Adapter/Imagick.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Varien/Image/Adapter/Imagick.php b/lib/Varien/Image/Adapter/Imagick.php index 08a23167acf..bcc87b3fcd6 100644 --- a/lib/Varien/Image/Adapter/Imagick.php +++ b/lib/Varien/Image/Adapter/Imagick.php @@ -125,7 +125,7 @@ public function save($destination = null, $newName = null) } /** - * @return string + * @inheritDoc */ public function display() {