numberkruncher
asked on
ImageMagick TIFF to JPEG - PHP
Hi guys,
Could somebody please tell me how to use ImageMagick to convert an image from tiff to jpeg, and then open it. Essentially it would be fantastic if somebody could fill in my tiff_to_jpeg function below:
Could somebody please tell me how to use ImageMagick to convert an image from tiff to jpeg, and then open it. Essentially it would be fantastic if somebody could fill in my tiff_to_jpeg function below:
function load_image($file_path, $mime) {
switch ($mime) {
case 'image/jpeg':
return imagecreatefromjpeg($file_path);
case 'image/png':
return imagecreatefrompng($file_path);
case 'image/gif':
return imagecreatefromgif($file_path);
case 'image/tiff':
tiff_to_jpeg($file_path);
return imagecreatefromjpeg($file_path.'.jpg');
}
}
function tiff_to_jpeg($file_path) {
// TIFF to JPEG at maximum uncompressed quality.
// Simply concatenate '.jpg' to file path...
}
Can you provide a sample of what $file_path would be set to? And where would the newly created file be placed? The web server process will need write access to that location.
ASKER
The web server process already has write access to that location as the file is uploaded and saved to wherever its destination may be.
$file_path could be any absolute path:
/home/vhosts/mydomain.com/ httpdocs/u ploads/fil e.tif
Output file:
/home/vhosts/mydomain.com/ httpdocs/u ploads/fil e.tif.jpg
$file_path could be any absolute path:
/home/vhosts/mydomain.com/
Output file:
/home/vhosts/mydomain.com/
I would probably want to have the output file named /home/vhosts/mydomain.com/ httpdocs/u ploads/fil e.jpg
But based on your requirements the following should work:
But based on your requirements the following should work:
function tiff_to_jpeg($file_path) {
// TIFF to JPEG at maximum uncompressed quality.
// Simply concatenate '.jpg' to file path...
system("convert " . $file_path . " " . $file_path . ".jpg");
}
ASKER
That seems to do the trick. Could you please tell me how to specify uncompressed maximum quality?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect! Thanks for the help!