Skip to content

Instantly share code, notes, and snippets.

@terwey
Created February 19, 2015 11:14
Show Gist options
  • Save terwey/0594905cd03e472679ff to your computer and use it in GitHub Desktop.
Save terwey/0594905cd03e472679ff to your computer and use it in GitHub Desktop.
PHP Imagick (ImageMagick) TIFF to JPG
// So ImageMagic is pretty cool, -but- it can sometimes consider a TIFF
// to be "metadata" that should be part of your thumbnailed JPG.
$Thumb = new \Imagick();
$Thumb->setResolution(72,72); // set the DPI of $Thumb to 72dpi, it's the WEB!
$data = file_get_contents('/data/some_image.jpg'); // secretly a TIFF pretending to be a JPG
// else make $data be something that came from curl_exec
$Thumb->readImageBlob($data);
$Thumb->setCompressionQuality(80); // you know, why have a 100compression quality thumbnail?
$Thumb->resampleImage(72,72,imagick::FILTER_UNDEFINED,1); // VERY IMPORTANT, without this it'll just "set" the DPI
// but not resample, so you are still stuck with a massive image
$Thumb->stripImage(); // Hey, here we remove the TIFF data from the JPG! Whoo 4MB saved
$image = $Thumb->getImageBlob(); // Here is our correctly resampled image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment