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:
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...
}

Open in new window

LVL 13
numberkruncherAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TRW-ConsultingCommented:
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.
numberkruncherAuthor Commented:
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/uploads/file.tif

Output file:
/home/vhosts/mydomain.com/httpdocs/uploads/file.tif.jpg
TRW-ConsultingCommented:
I would probably want to have the output file named /home/vhosts/mydomain.com/httpdocs/uploads/file.jpg

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");
}

Open in new window

Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

numberkruncherAuthor Commented:
That seems to do the trick. Could you please tell me how to specify uncompressed maximum quality?
TRW-ConsultingCommented:
Oh, sorry I forgot that.  Change

   system("convert " . $file_path . " " . $file_path . ".jpg");

 TO

  system("convert -quality 100 " . $file_path . " " . $file_path . ".jpg");

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
numberkruncherAuthor Commented:
Perfect! Thanks for the help!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.