• Resolved maddaze

    (@maddaze)


    As mentioned before, I have tens of thousands of photos of heritage sites, located in hundreds of towns. The photos come from multiple photographers. I need to retrieve photos by town, site and/or photographer.

    The purpose of this support ticket is to confirm, before I go to far, that what I have in mind will work.

    Given how the photos are organized on my computer (by photographer, town, and site within a town), I’m developing a PHP program to insert the photographer’s name into the IPTC of the photos before importing them into WPPA+. On import WPPA+ will preserve the town and site structure in the albums it creates and the IPTC will be loaded as a category. This is supposed to let me select photos by town and site with photos of the site by 1) any photographer or 2) just one photographer.

    Does that sound reasonable?

    Harvey

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Jacob N. Breetvelt

    (@opajaap)

    I’m developing a PHP program to insert the photographer’s name into the IPTC of the photos before importing them into WPPA+.

    I would very much want to know how you can add IPTC data into a photofile using PHP, but if you can do that, the IPTC data will be imported into wppa (just tick Table IX-H7) on upload/import.

    Once you have this data, a custom proc can be written to convert the required data into tags on the photos or categories in the albums.

    So, the answer is yes.

    However, a simpler method may be the ‘suersearch’ box, that will allow you to select on any content of any iptc tag. See https://wppa.nl/docs-by-subject/search/super-search/

    Thread Starter maddaze

    (@maddaze)

    OK, I’ll continue with the PHP programs. One is a class for handling IPTC metadata in images, the other is a program that uses the class to deal with my particular use case. I’ll try to add enough comments to make them understandable. Once both are working, I’ll pass them along to you.

    By the way, do you know where I can find a complete list of the IPTC code pairs, i.e;, Copyriht = 2#115? It’s not really important, because the partial lists I’ve found cover everuthjing I need. Still, out of idle curiosity, I’d be interested in seeing the complete list.

    And I’ll look at the supersearch box.

    Plugin Author Jacob N. Breetvelt

    (@opajaap)

    You can simply adapt this code for your needs:

    <?php
    // Add an IPTC or EXIF tag to a photo tag or album cat. Code to be inserted into Table VIII-B99: Custom Photo proc
    // This example adds IPTC tag 2#080 (photographer) as a tag to the photo and as a category to the album the photo is in
    
    $tag = '2#080';	// Specify the tag
    
    // Get the photos value for the tag. The IPTC/EXIF data must have been saved during upload/import_request_variables
    // For exif: use wppa_exif table as opposed to wppa_iptc in the next query
    $value = $wpdb->get_var( "SELECT description FROM $wpdb->wppa_iptc WHERE photo = $id AND tag = '$tag'" );
    
    // Process value only when not empty
    if ( $value ) {
    	
    	// Log value found
    	wppa_log( 'obs', 'Processing iptc/exif tag ' . $tag . ' with value ' . $value . ' for photo ' . $id );
    	
    	// Sanitize value
    	$value = str_replace( ',', '', $value ); // commas not allowed
    	
    	// Get existing tags
    	$old_tags = wppa_get_photo_item( $id, 'tags' );
    	$new_tags = wppa_sanitize_tags( $old_tags . ',' . $value ); // formats and removes duplicates
    	
    	// Save new tags to photo data
    	wppa_update_photo( array( 'id' => $id, 'tags' => $new_tags ) );
    	
    	// get the album
    	$alb = wppa_get_photo_item( $id, 'album' );
    	
    	// Get existing cats
    	$old_cats = wppa_get_album_item( $alb, 'cats' );
    	$new_cats = wppa_sanitize_cats( $old_cats . ',' . $value ); // formats and removes duplicates
    	
    	// Save new categories to album
    	wppa_update_album( array( 'id' => $alb, 'cats' => $new_cats ) );
    	
    }

    Before doing this, pls read the instructions: https://wppa.nl/docs-by-subject/advanced-topics/custom-code/

    For tags and cats: using the sanitize tags/cats functions is vital, as well as the removal of possible commas.
    he logfile (Table VIII-A1) tells you what has been done.

    To my knowledge, there is no ISO standard for IPTC tags, but more or less an agreement between vendors of photo editors.

    I use this list: (See wppa-exif-iptc-common.php line 3105)

    if ( $s == '2#005' ) $desc = 'Graphic name:';
    if ( $s == '2#010' ) $desc = 'Urgency:';
    if ( $s == '2#015' ) $desc = 'Category:';
    if ( $s == '2#020' ) $desc = 'Supp categories:';
    if ( $s == '2#040' ) $desc = 'Spec instr:';
    if ( $s == '2#055' ) $desc = 'Creation date:';
    if ( $s == '2#080' ) $desc = 'Photographer:';
    if ( $s == '2#085' ) $desc = 'Credit byline title:';
    if ( $s == '2#090' ) $desc = 'City:';
    if ( $s == '2#095' ) $desc = 'State:';
    if ( $s == '2#101' ) $desc = 'Country:';
    if ( $s == '2#103' ) $desc = 'Otr:';
    if ( $s == '2#105' ) $desc = 'Headline:';
    if ( $s == '2#110' ) $desc = 'Source:';
    if ( $s == '2#115' ) $desc = 'Photo source:';
    if ( $s == '2#120' ) $desc = 'Caption:';

    Note: The prefixes 2# for iptc and E# for exif is my addition to distinguish between the two types of hex numbers, and for the use as keywords in descriptions. They must be part of the data in the ‘tag’ column in both tables (wppa_exif and wppa_iptc).

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘IPTC and categories’ is closed to new replies.