changeset 51:549541f3e9c0

Possibly improve medium and thumbnail image generation by controlling Imagick components better.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 21 Jun 2016 14:21:53 +0300
parents 4ecdbe226155
children 5fbc443be538
files mgtool.php
diffstat 1 files changed, 13 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mgtool.php	Sat Jun 11 17:15:37 2016 +0300
+++ b/mgtool.php	Tue Jun 21 14:21:53 2016 +0300
@@ -55,6 +55,11 @@
   if ($img === FALSE)
     return mgError("ImageMagick could not digest the file '".$inFilename."'.\n");
 
+  $profiles = $img->getImageProfiles("icc", true);
+  $img->setImageDepth(16);
+  $img->transformImageColorspace(Imagick::COLORSPACE_SRGB);
+  $img->setImageColorspace(Imagick::COLORSPACE_SRGB);
+
   if ($outDim !== FALSE)
   {
     // Get dimensions, setup background
@@ -81,7 +86,7 @@
       // Image is larger
       $img->resizeImage($outDim[0], $outDim[1], Imagick::FILTER_LANCZOS, 1);
       $img->setImageExtent($outDim[0], $outDim[1]);
-      $img->normalizeImage();
+//      $img->normalizeImage();
       $img->unsharpMaskImage(0, 0.5, 1, 0.05);
     }
     if ($dim["width"] < $outDim[0] || $dim["height"] < $outDim[1])
@@ -89,14 +94,20 @@
       // Image is smaller than requested dimension(s)?
       $img->resizeImage($outDim[0], $outDim[1], Imagick::FILTER_LANCZOS, 1);
       $img->setImageExtent($outDim[0], $outDim[1]);
+//      $img->normalizeImage();
       $img->unsharpMaskImage(0, 0.5, 1, 0.05);
     }
   }
 
+
+  $img->setImageDepth(8);
   $img->setFormat($outFormat);
   $img->setCompressionQuality($outQuality);
+ 
+  $img->stripImage();
+  if (!empty($profiles))
+    $img->profileImage("icc", $profiles["icc"]);
 
-  $img->stripImage();
   $img->writeImage($outFilename);
   $img->removeImage();
   return TRUE;