• Reading the ideas here: https://www.ads-software.com/support/topic/exif-code-simplification?replies=2

    … I have finally moved away from using YAPB’s native EXIF display, which is not customizable in any way, other than selecting which tags you want to display. You can’t alter the tag names, you can’t alter the order, etc.

    I wish that YAPB had better EXIF parsing, like the old PhotoQ plugin, which gives much more control over EXIF tags and you can even convert EXIF tags to wordpress tags, so you could find all posts made with a certain camera or focal length, for example: https://github.com/andrewelkins/PhotoQ-WordPress-Photoblog-Plugin

    So I turned off YAPB’s EXIF, and did this instead:

    I put this in my theme’s functions.php file:

    // this function converts a fractional EXIF value to something we can use, see below where it's used to fix the format of the focal length
    
    function exif_get_float($value) {
      $pos = strpos($value, '/');
      if ($pos === false) return (float) $value;
      $a = (float) substr($value, 0, $pos);
      $b = (float) substr($value, $pos+1);
      return ($b == 0) ? ($a) : ($a / $b);
    } 
    
    // This function is used to determine the camera details for a specific image. It returns an array with the parameters.
    function cameraUsed($imagePath) {
    
      // The default empty array to return
        $return = array(
            'make'      => "",
            'model'     => "",
            'exposure'  => "",
            'aperture'  => "",
            'iso'       => "",
    	'date'       => "",
    	'lens'       => "",
    	'distance'       => "",
    	'focallength'       => "",
    	'focallength35'       => "",
    	'flashdata' => "",
    	'lensmake' => ""
        );
    
      // There are 2 arrays which contains the information we are after, so it's easier to state them both
        $exif_ifd0 = read_exif_data($imagePath ,'IFD0' ,0);
        $exif_exif = read_exif_data($imagePath ,'EXIF' ,0);
    
      // Ensure that we actually got some information
      if (($exif_ifd0 !== false) AND ($exif_exif !== false)) {
    
       // Camera Make
       if (@array_key_exists('Make', $exif_ifd0)) {
          $return['make']     = $exif_ifd0['Make'];
                }
    
      // Camera Model
      if (@array_key_exists('Model', $exif_ifd0)) {
          $return['model']    = $exif_ifd0['Model'];
                }
    
      // Exposure Time (shutter speed)
      if (@array_key_exists('ExposureTime', $exif_ifd0)) {
         $return['exposure'] = $exif_ifd0['ExposureTime'] . " sec.";
                }
    
      // Aperture
      if (@array_key_exists('ApertureFNumber', $exif_ifd0['COMPUTED'])) {
         $return['aperture'] = $exif_ifd0['COMPUTED']['ApertureFNumber'];
                }
    
      // ISO
      if (@array_key_exists('ISOSpeedRatings',$exif_exif)) {
          $return['iso'] = $exif_exif['ISOSpeedRatings'];
                }
    
      // Date
      if (@array_key_exists('DateTime', $exif_ifd0)) {
          $return['date'] = $exif_ifd0['DateTime'];
                }
    
      // Lens
      if (@array_key_exists('UndefinedTag:0xA434',$exif_exif)) {
          $return['lens'] = $exif_exif['UndefinedTag:0xA434'];
    		    }
    
      // Focus Distance
      if (@array_key_exists('FocusDistance', $exif_ifd0['COMPUTED'])) {
          $return['distance'] = $exif_ifd0['COMPUTED']['FocusDistance'];
    	        }
    
      // Focal Length
      if (@array_key_exists('FocalLength',$exif_exif)) {
    		$apex = exif_get_float($exif_exif['FocalLength']);
    		$flength = round($apex);
    		$return['focallength'] = $flength . " mm";
    		//$return['focallength'] = $exif_exif['FocalLength'];
    		    }
    
      // Focal Length 35mm
      if (@array_key_exists('FocalLengthIn35mmFilm',$exif_exif)) {
          $return['focallength35'] = $exif_exif['FocalLengthIn35mmFilm'] . " mm";
    		    }
    
      // Flash data
      if (@array_key_exists('Flash',$exif_exif)) {
    		// we need to interpret the result - it's given as a number and we want a human-readable description.  see WordPress's PhotoQ plugin's EXIF tools for more examples
    		$fdata = $exif_exif['Flash'];
    
    		if ($fdata == 0) $fdata = 'No Flash';
    		else if ($fdata == 1) $fdata = 'Flash';
    		else if ($fdata == 5) $fdata = 'Flash, strobe return light not detected';
    		else if ($fdata == 7) $fdata = 'Flash, strob return light detected';
    		else if ($fdata == 9) $fdata = 'Compulsory Flash';
    		else if ($fdata == 13) $fdata = 'Compulsory Flash, Return light not detected';
    		else if ($fdata == 15) $fdata = 'Compulsory Flash, Return light detected';
    		else if ($fdata == 16) $fdata = 'No Flash';
    		else if ($fdata == 24) $fdata = 'No Flash';
    		else if ($fdata == 25) $fdata = 'Flash, Auto-Mode';
    		else if ($fdata == 29) $fdata = 'Flash, Auto-Mode, Return light not detected';
    		else if ($fdata == 31) $fdata = 'Flash, Auto-Mode, Return light detected';
    		else if ($fdata == 32) $fdata = 'No Flash';
    		else if ($fdata == 65) $fdata = 'Red Eye';
    		else if ($fdata == 69) $fdata = 'Red Eye, Return light not detected';
    		else if ($fdata == 71) $fdata = 'Red Eye, Return light detected';
    		else if ($fdata == 73) $fdata = 'Red Eye, Compulsory Flash';
    		else if ($fdata == 77) $fdata = 'Red Eye, Compulsory Flash, Return light not detected';
    		else if ($fdata == 79) $fdata = 'Red Eye, Compulsory Flash, Return light detected';
    		else if ($fdata == 89) $fdata = 'Red Eye, Auto-Mode';
    		else if ($fdata == 93) $fdata = 'Red Eye, Auto-Mode, Return light not detected';
    		else if ($fdata == 95) $fdata = 'Red Eye, Auto-Mode, Return light detected';
    		else $fdata = 'Unknown: ' . $fdata;
    
          $return['flashdata'] = $fdata;
    		    }
    
      // Lens Make
      if (@array_key_exists('UndefinedTag:0xA433',$exif_exif)) {
          $return['lensmake'] = $exif_exif['UndefinedTag:0xA433'];
    		    }
    
      }
    	// Return either an empty array, or the details which we were able to extract
        return $return;
    
    }

    And I put the below in my theme template for the single post (in my case, single.php). This way, I decide the format (unordered list (ul/li tags)) and the order of the EXIF tags, and I can hide them (if(!empty) tests) if there is no data:

    <?php
    
    //get the full URL of the post's YAPB image
    $exifimg = site_url() . $post->image->uri;
    
    //use the function we created to get the EXIF data
    $camera = cameraUsed( $exifimg );
    
    //display the EXIF data using PHP and a whole lot of "echo"
    //note that quotes must be escaped by a backslash, see first line below
    
    //start an unordered list
    echo "<ul class=\"ul-exif\">";
    
    //generate the list items, if they exist
    if (!empty($camera['make'])) {
      echo "<li class=\"li-exif\">Camera Make: <i>" . $camera['make'] . "</i></li>";
    }
    if (!empty($camera['model'])) {
      echo "<li class=\"li-exif\">Camera Model: <i>" . $camera['model'] . "</i></li>";
    }
    if (!empty($camera['lensmake'])) {
      echo "<li class=\"li-exif\">Lens Make: <i>" . $camera['lensmake'] . "</i></li>";
    }
    if (!empty($camera['lens'])) {
      echo "<li class=\"li-exif\">Lens Model: <i>" . $camera['lens'] . "</i></li>";
    }
    if (!empty($camera['exposure'])) {
      echo "<li class=\"li-exif\">Shutter Speed: <i>" . $camera['exposure'] . "</i></li>";
    }
    if (!empty($camera['aperture'])) {
      echo "<li class=\"li-exif\">Aperture: <i>" . $camera['aperture'] . "</i></li>";
    }
    if (!empty($camera['iso'])) {
      echo "<li class=\"li-exif\">ISO Value: <i>" . $camera['iso'] . "</i></li>";
    }
    if (!empty($camera['focallength'])) {
      echo "<li class=\"li-exif\">Focal Length: <i>" . $camera['focallength'] . "</i></li>";
    }
    if (!empty($camera['focallength35'])) {
      echo "<li class=\"li-exif\">35mm-equiv.: <i>" . $camera['focallength35'] . "</i></li>";
    }
    if (!empty($camera['flashdata'])) {
      echo "<li class=\"li-exif\">Flash: <i>" . $camera['flashdata'] . "</i></li>";
    }
    if (!empty($camera['distance'])) {
      echo "<li class=\"li-exif\">Focus Distance: <i>" . $camera['distance'] . "</i></li>";
    }
    //close the unordered list
    echo "</ul>";
    ?>

    https://www.ads-software.com/plugins/yet-another-photoblog/

  • The topic ‘EXIF code simplicication – update’ is closed to new replies.