note 97016 deleted from function.imagick-cropthumbnailimage by danbrown

From: Date: Mon, 29 Mar 2010 00:39:22 +0000
Subject: note 97016 deleted from function.imagick-cropthumbnailimage by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-167476@lists.php.net to get a copy of this message
Note Submitter: Anonymous ---- If you are looking for a way to make a cropped thumbnail that maintains good quality and low file size, the below method may be good for you. I will reference the following functions: Imagick::setImageCompression Imagick::setImageCompressionQuality Imagick::stripImage Imagick::cropthumbnailImage Imagick::writeImage <?php $image = 'image.jpg'; $directory = '/path/to/image'; $image_location = $directory . "/" . $image; $thumb_destination = $directory . "/t" . $image; $compression_type = Imagick::COMPRESSION_JPEG; $im = new Imagick($image_location); $thumbnail = $im->clone; $thumbnail->setImageCompression($compression_type); $thumbnail->setImageCompressionQuality(40); $thumbnail->stripImage(); $thumbnail->cropthumbnailImage(100,100); $thumbnail->writeImage($thumb_destination); ?> NOTE: The Imagick::stripImage will remove all the EXIF data contained in the image. Some digital cameras will embed a thumbnail of their own in this data (if I remember correctly.) It is possible to actually extract the embedded thumbnail and use that if you would like. I have not tried it so I can't tell you about the file sizes. What I can tell you is by removing this data from the image I shaved quite a bit of data off of my images. If you would like to simply create a thumbnail that is not cropped check out the Imagick::thumbnailImage reference.

« previous php.notes (#167476) next »