note 97693 deleted from book.image by danbrown

From: Date: Mon, 03 May 2010 19:51:08 +0000
Subject: note 97693 deleted from book.image by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-168891@lists.php.net to get a copy of this message
Note Submitter: Anonymous ---- In reply to scurvysquid at yahoo dot com (04-May-2009) and Thomas (10-Dec-2008): I you want to use the GD library to resize your image, but want to keep exif data, you could use the PEL (PHP Exif Library) for that. It works like a charm for me. (Didn't test on TIFF files, but I guess it should work in a similar way.) <?php // filenames $src = 'img_src.jpg'; $dst = 'img_dst.jpg'; // for this example I just define x and y; $dst_x = 600; $dst_y = 400; // image quality $dst_q = 85; // resize image $img1 = imagecreatefromjpeg($src); $img2 = imagecreatetruecolor($dst_x, $dst_y); imagecopyresampled($img2, $img1, 0, 0, 0, 0, imagesx($img2), imagesy($img2), imagesx($img1), imagesy($img1)); imagejpeg($img2, $dst, $dst_q); // copy exif data from src to dst using PEL require_once('PelJpeg.php'); $jpeg_src = new PelJpeg($src); $exif_src = $jpeg_src->getExif(); $jpeg_dst = new PelJpeg($dst); $jpeg_dst->setExif($exif_src); // write result to file file_put_contents($dst, $jpeg_dst->getBytes()); ?> Note: Although PEL is presented as a pear package, there's no need to have pear installed on your server. You can download the library at http://pel.sourceforge.net/. Copy the php files to your includes dir (make sure the include_path directive contains the includes dir) or to the current directory, and use it.

« previous php.notes (#168891) next »