Thanks to Martin for his great PEL scripts.

I have found a weird bug which I do not manage to resolve - anyone's sharp
eyes would be most useful (btw, I have not found a way to post this question
on sourceforge's mailing list ? how I am supposed to post a new thread ?) :
depending on the source image (although both scanned images, saved in the
same way), my script runs correctly or crashes with the following error :

*Fatal error*: Uncaught exception 'PelDataWindowOffsetException' with
> message 'Offset 4780 not within [0, 4779]' in C:\Program
> Files\EasyPHP2\www\pel\PelDataWindow.php:243 Stack trace: #0 C:\Program
> Files\EasyPHP2\www\pel\PelDataWindow.php(401):
> PelDataWindow->validateOffset(4780) #1 C:\Program
> Files\EasyPHP2\www\pel\PelIfd.php(296): PelDataWindow->getLong(4780) #2
> C:\Program Files\EasyPHP2\www\pel\PelIfd.php(240):
> PelIfd->load(Object(PelDataWindow), 4742) #3 C:\Program
> Files\EasyPHP2\www\pel\PelTiff.php(164): PelIfd->load(Object(PelDataWindow),
> 8) #4 C:\Program Files\EasyPHP2\www\pel\PelExif.php(121):
> PelTiff->load(Object(PelDataWindow)) #5 C:\Program
> Files\EasyPHP2\www\pel\PelJpeg.php(244):
> PelExif->load(Object(PelDataWindow)) #6 C:\Program
> Files\EasyPHP2\www\pel\PelJpeg.php(315):
> PelJpeg->load(Object(PelDataWindow)) #7 C:\Program
> Files\EasyPHP2\www\pel\PelJpeg.php(163): PelJpeg->loadFile('1982-01-11
> Bous...') #8 C:\Program
> Files\EasyPHP2\www\pel\STC_script_date_FINAL.php(22):
> PelJpeg->__construct('1982-01-11 Bous...') #9 in *C:\Program
> Files\EasyPHP2\www\pel\PelDataWindow.php* on line *243*
>

Please find the script below and the 2 pictures at the following link :
http://idy.free.fr/pel_images/ - thanks a lot for your help !

Cheers,

Sebastian

<?php
> // Insert date / time EXIF data into image based on date provided in
> filename (format YYYY-MM-DD)
> // Use case : scanned pictures  which do not have any EXIF data. Manually
> entering date/time EXIF data alows better use of photo software like Picasa
> (Chronology function).
>
> // Display errors
> error_reporting(E_ALL);
>
> // Load PEL class
> require_once('PelJpeg.php');
> require_once('PelTiff.php');
>
> // Load image
>  $filename = "1982-01-11 Boussy.jpg";                // crashes
> // $filename = "1982-11-06 Boussy2.jpg";    // works well
>
> // Create object
> $jpeg = new PelJpeg($filename);
>
> // Get EXIF data
> $exif = $jpeg->getExif();
>
> // If no EXIF data
> if ($exif == null) {
>
> // Create EXIF data
> $exif = new PelExif();
> $jpeg->setExif($exif);
>
> $tiff = new PelTiff();
> $exif->setTiff($tiff);
>
> }
> else
> {
> $tiff = $exif->getTiff();
> }
>
> // Would exif data have not been null
> // $tiff = $exif->getTiff();
>
> $ifd0 = $tiff->getIfd();
>
> if ($ifd0 == null) {
> $ifd0 = new PelIfd(PelIfd::IFD0);
> $tiff->setIfd($ifd0);
> }
>
> $ifd1 = $ifd0->getSubIfd(PelIfd::EXIF);
> if ($ifd1 == null)
> {
> // Adding SubIFd
> $sub_exif = new PelIfd(PelIfd::EXIF);
> $ifd0->addSubIfd($sub_exif);
> $ifd1 = $ifd0->getSubIfd(PelIfd::EXIF);
> }
>
> // Point on date/time EXIF data
> $date = $ifd1->getEntry(PelTag::DATE_TIME_ORIGINAL);
>

> // Retrieve first 10 characters of the filename
> $year = substr($filename, 0, 4);
> $month = substr($filename, 5, 2);
> $day = substr($filename, 8, 2);
>
> // Convert these characters (which is a date) to a timestamp
> if (!gmmktime(0,0,0,$month,$day,$year)) {
> echo "Erreur dans la création du timestamp";
> }
> else {
>
> $new_date = gmmktime(12,0,0,$month,$day,$year);
>
> // Insert the new EXIF data to the same file
> if($date == null) {
> $date = new PelEntryTime(PelTag::DATE_TIME_ORIGINAL,$new_date);
> $ifd1->addEntry($date);
> }
> else
> {
> $date->setValue($new_date);
> }
> file_put_contents($filename, $jpeg->getBytes());
> echo "<br />Exif date updated successfully.<br /><br />";
> }
>
> ?>
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
PEL-devel mailing list
PEL-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pel-devel

Reply via email to