Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

PHP - convert tif to jpg and resize using ImageMagick

Posted on 2011-09-07
4
Medium Priority
?
2,116 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 111

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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Technology opened people to different means of presenting information, but PowerPoint remains to be above competition. Know why PPT still works today.
The viewer will learn how to dynamically set the form action using jQuery.
Add visuals to your Prezi to keep your audience engaged. Learn how to embed images, edit them, and more in this video micro tutorial. Select "Insert" from the top menu in your Prezi editor: Select "Image": A toolbar will pop in from the right …
Suggested Courses

636 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