• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2197
  • Last Modified:

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/';

$err = 0;
$run = exec($IM_path.'convert $tiff_file -resize 70x100 -quality 70 $thumb_file',$out,$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?
  • 2
1 Solution
try with simple method first

$exec = "convert /path/to/file.tiff /path/to/file.jpg";
exec($exec, $yaks);
//to view any errors >> // print_r($yaks);
Ray PaseurCommented:
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:

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?
aguawebdesignAuthor Commented:
Figured it out - I used single quotes around the exec command line.  Since it used PHP variables, I needed double quotes.  Changed that and it's now working.

Ray - great suggestion - I had proposed this solution to my client (to convert from TIFF beforehand), but the customer has a specific need to be uploading TIFF.
aguawebdesignAuthor Commented:
Was able to solve this on my own. Although the experts had some great suggestions, none of them directly solved the problem.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now