note 97693 added to book.image

From: Date: Mon, 03 May 2010 19:50:21 +0000
Subject: note 97693 added to book.image
Groups: php.notes 
Request: Send a blank email to php-notes+get-168890@lists.php.net to get a copy of this message
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. ---- Server IP: 91.199.167.223 Probable Submitter: 82.173.189.231 ---- Manual Page -- http://www.php.net/manual/en/book.image.php Edit -- https://master.php.net/note/edit/97693 Del: integrated -- https://master.php.net/note/delete/97693/integrated Del: useless -- https://master.php.net/note/delete/97693/useless Del: bad code -- https://master.php.net/note/delete/97693/bad+code Del: spam -- https://master.php.net/note/delete/97693/spam Del: non-english -- https://master.php.net/note/delete/97693/non-english Del: in docs -- https://master.php.net/note/delete/97693/in+docs Del: other reasons-- https://master.php.net/note/delete/97693 Reject -- https://master.php.net/note/reject/97693 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#168890) next »