Page 1 of 1

Imagick Use for thumbnailing

Posted: Wed Jan 28, 2009 3:55 pm
by Stacks
I'm trying to use imagick to display a thumbnailed image.

Code: Select all

 
header('Content-type: image/jpeg');
$image = new Imagick('image.jpg');
 
$image->thumbnailImage(100, 0);
echo $image;
 
 
This code works fine however I can' have this emedded within a php/html file. Because of calling the "header" I can't have anything else displayed in this file. Is there a way to display an imagick file without calling:

Code: Select all

header('Content-type: image/jpeg');
Or is there possibly another header call I can make to allow the html to work with the image. Thanks.

Re: Imagick Use for thumbnailing

Posted: Wed Jan 28, 2009 4:06 pm
by requinix
Make a PHP file just for displaying images, then put the image in your HTML with an <img>.

Code: Select all

<img src="thumb.php?name=image.jpg">

Code: Select all

<?php
 
header("Content-type: image/jpeg");
$image = new Imagick($_GET["name"]);
 
$image->thumbnailImage(100, 0);
echo $image;
 
?>
But it'd be a lot better if you could save those thumbnails to the server rather than generate them on-the-fly. Saves bandwidth and processing power - a win-win for everybody.

Re: Imagick Use for thumbnailing

Posted: Mon Feb 02, 2009 6:07 pm
by Stacks
Thank you very much. I didn't know you could link to a query string in an img tag, it is something I overlooked. This was a much simpler solution then my next step.

On a side note I have been pulling my query string variables out with the $_REQUEST variable rather then the $_GET variable. Is there a reason I should be using $_GET over $_REQUEST? Is that the right way to do it, or is it a matter of apples vs. oranges.

Thanks a million!