diff --git a/Rundiz/Image/Drivers/Imagick/Save.php b/Rundiz/Image/Drivers/Imagick/Save.php index 0586445..c5d8018 100644 --- a/Rundiz/Image/Drivers/Imagick/Save.php +++ b/Rundiz/Image/Drivers/Imagick/Save.php @@ -33,17 +33,14 @@ public function execute($file_name) // set compression. ----------------------------- if ($check_file_ext === 'jpg' || $check_file_ext === 'webp') { - // if save to JPG or WEBP. - if ($check_file_ext === 'jpg') { - $this->fillWhiteToImage(); - } + // if save as JPG or WEBP. $this->ImagickD->jpg_quality = intval($this->ImagickD->jpg_quality); if ($this->ImagickD->jpg_quality < 1 || $this->ImagickD->jpg_quality > 100) { $this->ImagickD->jpg_quality = 100; } $this->ImagickD->Imagick->setImageCompressionQuality($this->ImagickD->jpg_quality); } elseif ($check_file_ext === 'png') { - // if save to PNG. + // if save as PNG. $this->ImagickD->png_quality = intval($this->ImagickD->png_quality); if ($this->ImagickD->png_quality < 0 || $this->ImagickD->png_quality > 9) { $this->ImagickD->png_quality = 0; @@ -79,6 +76,11 @@ public function execute($file_name) // if source image is animated. $this->getFirstFrame(); } + + if ($check_file_ext === 'jpg') { + // if save as JPG. + $this->fillWhiteToImage(); + } $save_result = $this->ImagickD->Imagick->writeImage($file_name); }// endif; diff --git a/Rundiz/Image/Drivers/Imagick/Show.php b/Rundiz/Image/Drivers/Imagick/Show.php index df1156a..50c10db 100644 --- a/Rundiz/Image/Drivers/Imagick/Show.php +++ b/Rundiz/Image/Drivers/Imagick/Show.php @@ -37,9 +37,6 @@ public function execute($file_ext = '') // set compression. ----------------------------- if ($check_file_ext === 'jpg' || $check_file_ext === 'webp') { // if show as JPG or WEBP. - if ($check_file_ext === 'jpg') { - $this->fillWhiteToImage(); - } $this->ImagickD->jpg_quality = intval($this->ImagickD->jpg_quality); if ($this->ImagickD->jpg_quality < 1 || $this->ImagickD->jpg_quality > 100) { $this->ImagickD->jpg_quality = 100; @@ -87,6 +84,11 @@ public function execute($file_ext = '') // if source image is animated. $this->getFirstFrame(); } + + if ($check_file_ext === 'jpg') { + // if show as JPG. + $this->fillWhiteToImage(); + } $this->ImagickD->Imagick->setImageFormat($check_file_ext); $show_result = $this->ImagickD->Imagick->getImageBlob(); }// endif; diff --git a/Rundiz/Image/Drivers/Traits/ImagickTrait.php b/Rundiz/Image/Drivers/Traits/ImagickTrait.php index 20d246f..433018e 100644 --- a/Rundiz/Image/Drivers/Traits/ImagickTrait.php +++ b/Rundiz/Image/Drivers/Traits/ImagickTrait.php @@ -21,7 +21,7 @@ trait ImagickTrait */ protected function fillWhiteToImage() { - $this->ImagickD->Imagick->setImageBackgroundColor('white'); + $this->ImagickD->Imagick->setImageBackgroundColor(new \ImagickPixel('white')); $this->ImagickD->Imagick->setImageAlphaChannel(\Imagick::ALPHACHANNEL_REMOVE); }// fillWhiteToImage