Solved

PHP - convert tif to jpg and resize using ImageMagick

Posted on 2011-09-07
4
2,011 Views
Last Modified: 2012-05-12
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?
0
Comment
Question by:aguawebdesign
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 5

Expert Comment

by:amarpal0102
ID: 36500143
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);
?>
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 36502189
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?
0
 

Accepted Solution

by:
aguawebdesign earned 0 total points
ID: 36504865
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.
0
 

Author Closing Comment

by:aguawebdesign
ID: 36527926
Was able to solve this on my own. Although the experts had some great suggestions, none of them directly solved the problem.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Keep your audience engaged and get the most out of your next presentation with these quick Prezi tips.
Many programs have tried to outwit PowerPoint in terms of technology and skill. These programs, however, still lack several characteristics that PowerPoint has possessed from the start. Here's why PowerPoint replacements won't entirely work for desi…
Learn the basics of inputting and editing your text components in Prezi. We will cover how to set styles, position, and group your text components. In your Prezi editor, click anywhere on the canvas to add text: A flashing cursor informs you that yo…
Learn how to download your full Prezi presentation for offline presenting. Prezi doesn’t have to be viewed and shared in a web browser, even with a free account you can download your full presentation to share with others. Be sure to download any vi…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question