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

Hi!

> 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:

  ob_start();
  ImageJpeg($thumb);
  $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

Attachment: pgpDVUTtEI3C9.pgp
Description: PGP signature

-------------------------------------------------------------------------
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
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
PEL-devel mailing list
PEL-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pel-devel

Reply via email to