Solved

PHP - convert tif to jpg and resize using ImageMagick

Posted on 2011-09-07
4
1,827 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
  • 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 108

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo‚Ķ
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now