Support Requests item #1815728, was opened at 2007-10-18 14:05
Message generated for change (Comment added) made by mgeisler
You can respond by visiting:

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: None
Group: None
>Status: Closed
Priority: 5
Private: No
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Nobody/Anonymous (nobody)
Summary: adding EXIF Information from scratch 

Initial Comment:

I wrote this function, adding EXIF Information from the scratch to a JPG-Image.

Unfortunately in the second GPS entry, the minutes and seconds are missing. If 
longitude is the second then its missing there, if i switch their places its 
missing in latitude? It doesnt make any sense, so ... well i'm asking for help 
here :)

Here's the function (with german comments):

function add_EXIFinfo(  
        $filename = "filename.jpg Default",
        $description ="DESCRIPTION Default",
        $USER_COMMENT ="USER_COMMENT Default",
        $MODEL ="MODEL Default",
        $GPS_VERSION_ID ="123",
        $GPS_LONGITUDE = 0,
        $GPS_LATITUDE = 0,
        $GPS_LONGITUDE_REF = "E",
        $GPS_LATITUDE_REF = "N",
        $GPS_ALTITUDE  = array(0, 0, 0),
        $GPS_ALTITUDE_REF = 0) {
        $GPS_LONGITUDE = convertGps($GPS_LONGITUDE);
        $GPS_LATITUDE = convertGps($GPS_LATITUDE);
        $jpeg = new PelJpeg($filename); //Ein PelJpeg Objekt wird erstellt (mit 
dem gegebenen JPG)
        $exif = new PelExif(); //Exif Objekt wird erstellt
        $jpeg->setExif($exif); //Exif Objekt wird dem JPG hinzugefügt
        $tiff = new PelTiff(); // Tiff Objekt wird erzeugt (Tiff Objekt enthält 
exif info)
        $exif->setTiff($tiff); //Dem Exif-Objekt wird das Tiff Objekt zugewiesen
        $ifd0 = $tiff->getIfd(); //erste Exif-Info wird aus dem tiff Obj 
herausgelesen ( müsste "null" sein)
        if ($ifd0 == null) {
          $ifd0 = new PelIfd(PelIfd::IFD0);
        $GPSSubIFD = new PelIfd(PelIfd::GPS); //SubIFD für GPS-Informationen 
wird erstellt.
        $ifd0->addSubIfd($GPSSubIFD); //dem Ifd0 wird GPS sub IFD hinzugefügt
        $EXIFSubIFD = new PelIfd(PelIfd::EXIF); //SubIFD für EXIF-Informationen 
wird erstellt.
        $ifd0->addSubIfd($EXIFSubIFD); //dem Ifd0 wird EXIF sub IFD hinzugefügt
        $INTOSubIFD = new PelIfd(PelIfd::INTEROPERABILITY); //SubIFD für 
INTEROPERABILITY-Informationen wird erstellt.
        $ifd0->addSubIfd($INTOSubIFD); //dem Ifd0 wird INTEROPERABILITY sub IFD 
        echo "USER_COMMENT wird geschrieben<br>";
        $exif_entry = new PelEntryUserComment($USER_COMMENT);
        echo "MODEL wird geschrieben<br>";
        $exif_entry = new PelEntryAscii(PelTag::MODEL, $MODEL);
        echo "IMAGE_DESCRIPTION wird geschrieben<br>";
        $desc = new PelEntryAscii(PelTag::IMAGE_DESCRIPTION, $description);
        echo "GPS_VERSION_ID wird geschrieben<br>";
        $exif_entry = new PelEntryByte(PelTag::GPS_VERSION_ID,$GPS_VERSION_ID);
        echo "GPS_LATITUDE_REF wird geschrieben<br>";
        $exif_entry = new PelEntryAscii(PelTag::GPS_LATITUDE_REF, 
        echo "GPS_LATITUDE wird geschrieben<br>";
        $exif_entry = new PelEntryRational(PelTag::GPS_LATITUDE, $GPS_LATITUDE);
        echo "GPS_LONGITUDE_REF wird geschrieben<br>";
        $exif_entry4 = new PelEntryAscii(PelTag::GPS_LONGITUDE_REF, 

        echo "GPS_LONGITUDE wird geschrieben<br>";
        $exif_entry = new PelEntryRational(PelTag::GPS_LONGITUDE, 
        echo "GPS_ALTITUDE wird geschrieben<br>";
        $exif_entry = new PelEntryRational(PelTag::GPS_ALTITUDE, $GPS_ALTITUDE);
        echo "GPS_ALTITUDE_REF wird geschrieben<br>";
        $exif_entry = new PelEntryAscii(PelTag::GPS_ALTITUDE_REF, 
        $file = basename($filename);  
        file_put_contents("tagged_pics/".$file, $jpeg->getBytes());


>Comment By: Martin Geisler (mgeisler)
Date: 2007-10-18 20:10

Logged In: YES 
Originator: NO

Nice that figured it out by yourself -- the rationals are not the easies
class to work with.

The script looks good, I just have one comment: the if statement is not
needed since an empty PelTiff object contains no PelIfd object to begin
with. So the test is always true and can be skipped.

I'll close the request now -- please drop by on the pel-devel mailing list
if you have suggestions as to how we can make PEL easier to use. Maybe we
should package your script up as an example? It would be great if you could
turn it into a self-contained unit (I saw it uses a convertGps function)
then I would like to include it.

Also, please note that I have never really tested the GPS tags myself
since I don't have any GPS equipment. So any help there is much


Comment By: Nobody/Anonymous (nobody)
Date: 2007-10-18 16:28

Logged In: NO 

ok.. got it myself:
$exif_entry = new PelEntryRational(PelTag::GPS_LATITUDE, $GPS_LATITUDE);

is wrong,

$exif_entry = new PelEntryRational(PelTag::GPS_LATITUDE, array(

is right ;)

thx anyway.... btw, nice function, isnt it? ;)


Comment By: Nobody/Anonymous (nobody)
Date: 2007-10-18 14:09

Logged In: NO 

And i use EXIFReader to ckeck the Exif-Data in the Jpeg..

Best regards,



You can respond by visiting:

This email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>
PEL-devel mailing list

Reply via email to