Link to home
Start Free TrialLog in
Avatar of aguawebdesign
aguawebdesignFlag for United States of America

asked on

PHP - convert tif to jpg and resize using ImageMagick

I am using ImageMagick 6.7.1-7, installed on a Linux server.  I have a tif image that needs to be converted to jpg and then resized to a thumbnail.

Here is the code I have so far:

 
$url = "/home/notie0/public_html/images/models/highres/231/";
$thumb_file = $url . 'thumbs/sample.jpg';
$tiff_file = $url . 'sample.tif';
$IM_path = '/usr/bin/';

$out=array();
$err = 0;
$run = exec($IM_path.'convert $tiff_file -resize 70x100 -quality 70 $thumb_file',$out,$err);
print_r($out);
print_r($err);

Open in new window


No image is being returned. I am showing an error code of 1, but no error message (empty array).  Any ideas how to fix this?
Avatar of amarpal0102
amarpal0102
Flag of New Zealand image

try with simple method first

<?php
$exec = "convert /path/to/file.tiff /path/to/file.jpg";
exec($exec, $yaks);
//to view any errors >> // print_r($yaks);
?>
I guess my first idea would be to load the TIFF image into Photoshop and save it in a more commonly used format.  A Photoshop "action" could be used to convert a library if you have more than one TIFF file.  Or you might try some of the techniques described here:
http://stackoverflow.com/questions/1973719/how-to-convert-tiff-to-png-jpg-bmp-in-php

After you have converted the TIFF to another format (I recommend PNG because it is not a "lossy" compression) it is easy to create a thumbnail in PHP.  Would you be OK with the GD library functions for this part of the process?
ASKER CERTIFIED SOLUTION
Avatar of aguawebdesign
aguawebdesign
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of aguawebdesign

ASKER

Was able to solve this on my own. Although the experts had some great suggestions, none of them directly solved the problem.