note 106345 added to function.imagick-thumbnailimage

From: Date: Sat, 29 Oct 2011 15:31:04 +0000
Subject: note 106345 added to function.imagick-thumbnailimage
Groups: php.notes 
Request: Send a blank email to php-notes+get-184216@lists.php.net to get a copy of this message
Even though thumbnailImage is meant to produce the smallest file size image possible, i found it didn't. I put together this code and bordering different compression settings, found it produced the smallest file size: <?php // Max vert or horiz resolution $maxsize=550; // create new Imagick object $image = new Imagick('input_image_filename_and_location'); // Resizes to whichever is larger, width or height if($image->getImageHeight() <= $image->getImageWidth()) { // Resize image using the lanczos resampling algorithm based on width $image->resizeImage($maxsize,0,Imagick::FILTER_LANCZOS,1); } else { // Resize image using the lanczos resampling algorithm based on height $image->resizeImage(0,$maxsize,Imagick::FILTER_LANCZOS,1); } // Set to use jpeg compression $image->setImageCompression(Imagick::COMPRESSION_JPEG); // Set compression level (1 lowest quality, 100 highest quality) $image->setImageCompressionQuality(75); // Strip out unneeded meta data $image->stripImage(); // Writes resultant image to output directory $image->writeImage('output_image_filename_and_location'); // Destroys Imagick object, freeing allocated resources in the process $image->destroy(); ?> I found setCompression to not function at all and had to use setImageCompression. The stripImage call is needed and strips out unneeded meta data. You can choose whatever filter you want, but i found lanczos to be the best for image reduction, though it is more computationally heavy. ---- Server IP: 69.147.83.197 Probable Submitter: 70.62.232.146 ---- Manual Page -- http://www.php.net/manual/en/function.imagick-thumbnailimage.php Edit -- https://master.php.net/note/edit/106345 Del: integrated -- https://master.php.net/note/delete/106345/integrated Del: useless -- https://master.php.net/note/delete/106345/useless Del: bad code -- https://master.php.net/note/delete/106345/bad+code Del: spam -- https://master.php.net/note/delete/106345/spam Del: non-english -- https://master.php.net/note/delete/106345/non-english Del: in docs -- https://master.php.net/note/delete/106345/in+docs Del: other reasons-- https://master.php.net/note/delete/106345 Reject -- https://master.php.net/note/reject/106345 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#184216) next »