Use EXIF Data As Image Attributes

In this doc we will look at creating a custom attribute tag for Image Attributes Pro that reads the EXIF data from each image.

You can use the bulk updater and update image title, alt text, caption or description with EXIF data from your images.

To create the custom attribute tag %exif_data% add the following code to the functions.php of your active theme.

/**
 * Custom tag %exif_data% for Image Attributes Pro.
 * 
 * @param $image_id The ID of the image that is being updated. 
 * @param $parent_post_id The post to which the image is attached (uploaded) to. 
 * @param $bulk True when called from Bulk Updater. False by default.
 * 
 * @return string EXIF data or empty string if no data is found.
 * 
 * @refer https://imageattributespro.com/codex/iaffpro_get_custom_attribute_tag_tagname/
 */
function iaffpro_get_custom_attribute_tag_exif_data( $image_id, $parent_post_id, $bulk = false ) {

	$image_url = wp_get_attachment_url( $image_id );
	$exif_data = @exif_read_data( $image_url );

	if ( $exif_data === false ) {
		return '';
	}

	/**
	 * Refer to this example EXIF data for more EXIF data sources:
	 * https://gist.github.com/arunbasillal/7969b387ef970f4c99b4fdcbc77f7842
	 */
	if ( isset( $exif_data['Make'] ) ) {
		return $exif_data['Make'];
	}

	return '';
}

Now you will be able to use %exif_data% as custom attribute tag in Image Attributes Pro settings.

Custom Attribute Tag Exif_data

Things To Note

  • EXIF data can have various attributes. An example of what that looks like is available here.
  • In the above example, Make (Camera Make) is used as the EXIF data. You might have to change this based on your requirement.
  • To do so, please replace $exif_data['Make'] in the above code with your requirement.
  • The example data will give you a guideline on what attribute to use.
  • For example, to use Camera Model instead of Camera Make, use $exif_data['Model'] instead of $exif_data['Make'].
  • Reading EXIF data is a resource intensive process. So batch processing of images can take longer than usual.

If you have questions, please do not hesitate to get in touch.