php question

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
nonaguy

php question

Post by nonaguy »

I am building an application for viewing 60,000+ images. These images are all stored as tiffs. What I would like to do is in my application, someone uses a form to select whatever image they wish to view, and I would like to run a php script that would convert the tiff to jpeg and resize it to thumbnail size and echo the jpeg out to the viewer.

In other words, I want to load the tiff in memory, convert and resize in memory, and echo out the result, without writing anything to the original image. I am somewhat new to php and I would appreciate any help you can provide. Thank you.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: php question

Post by Bonzo »

You can check my site for examples of IM and php.

Check this page for displaying an image without saving it: http://www.rubblewebs.co.uk/imagemagick ... isplay.php

This is the code you can use; it can be simplified if you are always using the same dimensions.

Code: Select all

<?php
$photo="../code/sunflower.jpg";
$THUMB_SZ  = 125;
$THUMB_PRESZ  = $THUMB_SZ * 2;
$QUALITY = 87;
$cmd = "convert -size $THUMB_PRESZ".'x'."$THUMB_PRESZ \"$photo\"" .
" -resize $THUMB_SZ".'x'."$THUMB_SZ" .
" -strip" .
" -unsharp 0.2x0.6+1.0" .
" -quality $QUALITY JPG:-";

header("Content-type: image/jpeg");
passthru($cmd, $retval);
?>
nonaguy

Re: php question

Post by nonaguy »

Thank you, the code works great for what we need it to do.
Post Reply