|
List Info
Thread: PelIfd.setThumbnail (PelDataWindow $d) doesn't work!
|
|
| PelIfd.setThumbnail (PelDataWindow $d)
doesn't work! |

|
2006-12-21 14:36:37 |
|
| 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
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 file_put_contents("./out.jpg",$jpeg->getBytes());
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)); ob_start(); ImageJpeg($ret_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.
Regards,
VanPH.
-----Original Message----- From:
pel-devel-bounces lists.sourceforge.net [lists.sourceforge.net">mailto:pel-devel-bounces lists.sourceforge.net]
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"
<van smartsolutions.com.vn> 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:ProjectsMIPWIPSourceMIP-ServerlibpelPelDataWindow.php:243 >
Stack trace: #0 >
D:ProjectsMIPWIPSourceMIP-ServerlibpelPelDataWindow.php(303): >
PelDataWindow->validateOffset(-1) #1 >
D:ProjectsMIPWIPSourceMIP-ServerlibpelPelIfd.php(549): >
PelDataWindow->getByte(-1) #2 >
D:ProjectsMIPWIPSourceMIP-Serverwebthumb.php(17): >
PelIfd->setThumbnail(Object(PelDataWindow)) #3 thrown in >
D:ProjectsMIPWIPSourceMIP-ServerlibpelPelDataWindow.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 ---
<mgeisler mgeisler.net> --- 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
|
[1]
|
|
|
about | contact Other archives ( Real Estate discussion Medical topics )
|