July 12, 2008 2:33 pm GMT
Create thumbnails on-the-fly using Imagick
by Gary IllyesOK, this will be simple. I said it’s simple, more simpler than anyone can expect. Let’s see the overcomplicated code:
<?php $im = new Imagick( 'path/to/your/image.jpg' ); $im->thumbnailImage( 200, null ); header( "Content-Type: image/jpg" ); echo $im; ?>
That was all. Yup.
OK, now step by step:
- We instruct Imagick to work with the file from the parameter.
- Ask nicely Imagick to create a thumbnail: width should be 200px and no fixed height. That’s good, cos Imagick will automatically preserve the aspect ratio, so, bye-bye ugly thumbnails
- Set the correct Content-type header
- echo() the Imagick object which contains the image data, namely $im
That’s all. We saved the world again…
If something is not clear, the comments are open, just ask and will try to answer as soon as possible.
















Comments
Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!
If you want to use your OpenID, fill out the field labeled "Website" with the OpenID URL. The other fields may remain empty.
Note that comments are pre-moderated.