Convert RAW photos to JPEG in linux/php

David picture David · May 11, 2012 · Viewed 18.4k times · Source

I'm working on an photo upload app and need to allow users to upload raw files from cameras (these are not jpegs) and have the server automatically create a jpeg version of them. I currently have Imagemagick installed but I don't think there is a way to do it in there.

Cameras come out with new raw formats all the time, so im looking for something that will be relativley up-to-date and command php exec() is an option too.

Does anyone have anything to suggestion for raw conversion?

Answer

Jeroen picture Jeroen · May 11, 2012

Actually, as you can see in this list, ImageMagick does support RAW photos: http://www.imagemagick.org/script/formats.php (e.g. .NEF nikon photos and .CR2 canon photos).

Example code for a .CR2 photo:

$im = new Imagick( 'source.CR2' );
$im->setImageFormat( 'jpg' );
$im->writeImage( 'result.jpg' );
$im->clear();
$im->destroy();