Mittwoch, 22. Oktober 2025

IPCT Daten von Medien mit PHP iptcparse auslesen

IPTC Daten können in Bilder geschrieben werden 

IPTC Daten können Sie im Gegensatz zu EXIF Daten selbst z.B. mit XnView in Bilder schreiben. Viele Programme oder Apps können die IPTC Daten auch auslesen. Mit den IPTC Daten werden so Ihre persönlichen Eintragungen mit dem Bild / Photo weitervermittelt, ohne daß Sie umständlich darauf eingehen müssen. Einmal eingetragen immer dabei auch in Jahren noch, wenn Sie schon nicht mehr wissen, wo Sie das Foto eigentlich geschossen haben. Deshalb lohnt es sich für Gallerien im World Wide Web mit den IPTC Daten zu befassen

IPTC Daten: 

IPTC steht für International Press Telecommunications Council und bezieht sich auf standardisierte Metadaten, die in digitalen Medien wie Bildern gespeichert werden, um Informationen über deren Inhalt, Herkunft und Rechte bereitzustellen. Diese Daten sind nicht sichtbar, sondern in der Datei hinterlegt und umfassen beispielsweise Bildunterschriften, Copyright-Hinweise und Informationen zum Fotografen. 

>> Weiterlesen: https://de.wikipedia.org/wiki/IPTC-IIM-Standard

Passende Einstiege waren nur schwer zu finden, die hier aufgeführten Code Snippets stammen alle von PHP.NET und waren mir sehr nützlich -->

https://www.php.net/manual/de/function.iptcparse.php


View all availiable IPCT Data

function output_iptc_data( $image_path ) {    
    $size = getimagesize ( $image_path, $info);        
     if(is_array($info)) {    
        $iptc = iptcparse($info["APP13"]);
        foreach (array_keys($iptc) as $s) {              
            $c = count ($iptc[$s]);
            for ($i=0; $i <$c; $i++) 
            {
                echo $s.' = '.$iptc[$s][$i].'<br>';
            }
        }                  
    }             
}

 


This took me longer than it ought to to figure out. Very handy for handling a stream of photos where the info you want is in the IPTC header. This example passes by reference, for which PHP4 will yell at you. If your need to write into the header, check out the Image::IPTCInfo Perl module.

$size = GetImageSize ("$image_name",&$info);

$iptc = iptcparse ($info["APP13"]);

if (isset($info["APP13"])) {

    $iptc = iptcparse($info["APP13"]){

        if (is_array($iptc)) {

        $caption = $iptc["2#120"][0];

    $graphic_name = $iptc["2#005"][0];

        $urgency = $iptc["2#010"][0];    

    $category = $iptc["2#015"][0];    

    // note that sometimes supp_categories contans multiple entries

$supp_categories = $iptc["2#020"][0];

$spec_instr = $iptc["2#040"][0];

$creation_date = $iptc["2#055"][0];

$photog = $iptc["2#080"][0];

$credit_byline_title = $iptc["2#085"][0];

$city = $iptc["2#090"][0];

$state = $iptc["2#095"][0];

$country = $iptc["2#101"][0];

$otr = $iptc["2#103"][0];

$headline = $iptc["2#105"][0];

$source = $iptc["2#110"][0];

$photo_source = $iptc["2#115"][0];

$caption = $iptc["2#120"][0];    }}

I've managed to update "pkrohn at daemonize dot com" array, after 12 years since initial publication.



If you want to change some of IPCT header-strings into something more human-readable, try to use array similar to this:

$iptcHeaderArray = array
(
    '2#005'=>'DocumentTitle',
    '2#010'=>'Urgency',
    '2#015'=>'Category',
    '2#020'=>'Subcategories',
    '2#040'=>'SpecialInstructions',
    '2#055'=>'CreationDate',
    '2#080'=>'AuthorByline',
    '2#085'=>'AuthorTitle',
    '2#090'=>'City',
    '2#095'=>'State',
    '2#101'=>'Country',
    '2#103'=>'OTR',
    '2#105'=>'Headline',
    '2#110'=>'Source',
    '2#115'=>'PhotoSource',
    '2#116'=>'Copyright',
    '2#120'=>'Caption',
    '2#122'=>'CaptionWriter'
);

Keine Kommentare:

Kommentar veröffentlichen