I resend my last email with the link to sample image.
Also i tried to getThumbnailData by: $oldThumb = $ifd0->getThumbnailData();
and get a zero length result all the time. Any idea? i use Photostudio to
check exif info


From: Pham Hoai Van [mailto:[EMAIL PROTECTED] 
Sent: Thursday, December 21, 2006 12:11 AM
To: 'Discussions on the development of PEL'
Subject: RE: [PEL] PelIfd.setThumbnail (PelDataWindow $d) doesn't work!

Hi Martin,
Thanks for your answer. It still doesnt work although i update latest
version of PEL from svn and change my code as follow:

//insert to img
$jpeg = new PelJpeg("./I1.JPG"); 
$exif = $jpeg->getExif();
$tiff = $exif->getTiff();
$ifd0 = $tiff->getIfd();
//create thumbnail img
$img = imagecreatefromjpeg("./I1.JPG");
$thumb = create_thumbnail_image($img, 0.1); //create a thumbnail image with
size = 10% of its org
$ifd0->setThumbnail(new PelDataWindow($thumb));
//write to file
function create_thumbnail_image($source_img, $zoom_percent)
//calculate new width and height
// $width = imagesx($source_img)*$zoom_percent;
// $height = imagesy($source_img)*$zoom_percent;
$width = 160; 
$height = 120;
//create return img
$ret_img = imagecreatetruecolor($width, $height) 
or die ('can not create new image');
imagecopyresampled($ret_img, $source_img,
0, 0, 0, 0, $width, $height, imagesx($source_img), imagesy($source_img));
return ob_get_clean();

This time no exception is thrown but it seems the original thumbnail image
is not replaced with the new one. Maybe it's just appended. You can see it
in the attached image. FYI, i wanna set new thumbnail image because after
some manipulations on image received from a mobile device, the exif info is
lost. So i need to add it again at the server side.

-----Original Message-----
[mailto:[EMAIL PROTECTED] On Behalf Of Martin Geisler
Sent: Wednesday, December 20, 2006 10:55 PM
To: pel-devel@lists.sourceforge.net
Subject: Re: [PEL] PelIfd.setThumbnail (PelDataWindow $d) doesn't work!

"Pham Hoai Van" <[EMAIL PROTECTED]> writes:


> First, I wanna say thank you to the founders of this very nice open
> source PEL.

Thanks, I appreciate it!

> Second, I have a problem regarding setThumbnail img and need your
> helps. Here is my code:
> //------------------------------------------------------------------
> //create thumbnail img
> $img = imagecreatefromjpeg("./I1.JPG");
> $thumb = create_thumbnail_image($img, 0.1); //create a thumbnail
>                                 //image with size = 10% of its org
> //insert new thumbnail to img
> $jpeg = new PelJpeg();
> $jpeg->loadFile("./I1.JPG"); 

Just a hint: you can now simply do $jpeg = new PelJpeg("./I1.JPG"); and PEL
will load the data from the file.

> $exif = $jpeg->getExif();
> $tiff = $exif->getTiff();
> $ifd0 = $tiff->getIfd();
> $ifd0->setThumbnail(new PelDataWindow($thumb));
> $jpeg->setExif($exif);

Another hint: this is not necessary (it does nothing in this case).
When the $exif object is changed, then $jpeg will see the change as well
since $jpeg has a reference (pointer) to $exif.

> Running above code, I got this exception:
> Fatal error: Uncaught exception 'PelDataWindowOffsetException' with
> message 'Offset -1 not within [0, 14]' in
> D:\Projects\MIP\WIP\Source\MIP-Server\lib\pel\PelDataWindow.php:243
> Stack trace: #0
> D:\Projects\MIP\WIP\Source\MIP-Server\lib\pel\PelDataWindow.php(303):
> PelDataWindow->validateOffset(-1) #1
> D:\Projects\MIP\WIP\Source\MIP-Server\lib\pel\PelIfd.php(549):
> PelDataWindow->getByte(-1) #2
> D:\Projects\MIP\WIP\Source\MIP-Server\web\thumb.php(17):
> PelIfd->setThumbnail(Object(PelDataWindow)) #3 {main} thrown in
> D:\Projects\MIP\WIP\Source\MIP-Server\lib\pel\PelDataWindow.php on
> line 243
> This is due to a incorrect $thumb data is set to the PelDataWindow
> constructor. What kind of thumbnail data will I need to set to the
> PelDataWindow constructor? Any idea will be much appreciated. Thank
> you.

The thumbnail data is supposed to be JPEG normal data, wrapped in a
PelDataWindow. I assume your create_thumbnail_image() function return an
Image resource like the ImageCreateFromJpeg() function?

If so, then you need to extract the JPEG data from this resource. I've just
committed some code that will let you do what you tried:
construct a PelDataWindow from an image resource. So you can update From SVN
and it should work.

Or you can use this piece of code:

  $window = new PelDataWindow(ob_get_clean());

$window now has your data and you should be able to use it with the
setThumbnail() method.

As a side remark, then why do you want to update the thumbnail? The Exif
standard indicates that the thumbnail should always be 160x120 pixels.
You're not even allowed to rotate it which is kind of silly...

Anyway, please let me know if the new code works as expected.

Martin Geisler  ---  <[EMAIL PROTECTED]>  ---  http://mgeisler.net

Read, write, create Exif data in PHP with PEL:       http://pel.sf.net
Take control of your webserver with PHP Shell:  http://phpshell.sf.net

Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
PEL-devel mailing list

Reply via email to