Skip to content
Advertisement

Convert tiff to jpg in php?

I have a server which holds TIFF images. Most clients can read and display TIFF images, so there’s no problem. However, some clients can’t handle this format but can handle JPG. I thought of using PHP’s GD library to do a server side conversion for clients without TIFF reading abilities. But I noticed GD can’t read TIFF files too.

Imagick not working in windows, My idea was to create an imageFetcher.php which gets as a parameter the actual image the client wants. It checks the client’s type and if needed converts the image and outputs a JPG, otherwise it simply outputs the TIFF.

does anyone have any idea on how I could do such a thing?

Thanks in advance.

Advertisement

Answer

In the forum at http://www.php.net/gd the following comment is written:

IE doesn’t show TIFF files and standard PHP distribution doesn’t support converting to/from TIFF.

ImageMagick (http://www.imagemagick.org/script/index.php) is a free software that can read, convert and write images in a large variety of formats. For Windows users it includes a PHP extension php_magickwand_st.dll (and yes, it runs under PHP 5.0.4).

When converting from TIFF to JPEG, you must also convert from CMYK color space to RGB color space as IE can’t show CMYK JPGs either. Please note: -TIFF files may have RGB or CMYK color space -JPEG files may have RGB or CMYK color space

Here are example functions using ImageMagick extension: – convert TIFF to JPEG file formats – convert CMIK to RGB color space – set image resolution to 300 DPIs (doesn’t change image size in pixels)

JavaScript

Note – Although ImageMagick correctly sets JPEG files resolution to 300 DPIs, some programs might not notice it.

ELSE

Use the “imagick” PECL extension

http://pecl.php.net/package/imagick

http://php.net/manual/en/book.imagick.php

Depending on sources and destinations (files? urls? http response?) you’ll do something like:

JavaScript

OR

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement