WordPress.org

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/wp read image metadata

Description

Get extended image metadata, exif or iptc as available.

Retrieves the EXIF metadata aperture, credit, camera, caption, copyright, iso created_timestamp, focal_length, shutter_speed, and title.

The IPTC metadata that is retrieved is APP13, credit, byline, created date and time, caption, copyright, and title. Also includes FNumber, Model, DateTimeDigitized, FocalLength, ISOSpeedRatings, and ExposureTime.

Usage

<?php wp_read_image_metadata$file ); ?>

Parameters

$file
(string) (required)
Default: None

Must pass in file path to image

Return Values

(boolean|array) 
False on failure. Image metadata array on success.

The elements returned in the array are:

["aperture"] 
(string) Set to the EXIF FNumber field.
["credit"] 
(string) Set to the first non-empty value found by looking through the following fields:
  1. IPTC Credit field (2#110)
  2. IPTC Creator field (2#080)
  3. EXIF Artist field
  4. EXIF Author field
["camera"] 
(string) Set to the EXIF Model field.
["caption"] 
(string) Set to a non-empty value of one of the following fields (see source code for the precise logic involved):
  1. IPTC Description field (2#120)
  2. EXIF UserComment field if ["title"] is unset AND EXIF:ImageDescription is less than 80 characters
  3. EXIF ImageDescription field if ["title"] is set OR EXIF:ImageDescription is more than 80 characters
  4. EXIF Comments field if ["title"] does not equal EXIF:Comments
["created_timestamp"] 
(string) Set to the first non-empty value found by looking through the following fields:
  1. EXIF field DateTimeDigitized
  2. IPTC Date and Time fields (2#055 and 2#060)
["copyright"] 
(string) Set to the first non-empty value found by looking through the following fields:
  1. IPTC Copyright field (2#116)
  2. EXIF Copyright field
["focal_length"] 
(string) Set to the EXIF FocalLength field.
["iso"] 
(string) Set to the EXIF ISOSpeedRatings field.
["shutter_speed"] 
(string) Set to the EXIF ExposureTime field.
["title"] 
(string) Set to the first non-empty value found by looking through the following fields:
  1. IPTC Headline field (2#105)
  2. IPTC Title field (2#005)
  3. IPTC Description field (2#120) but only if less than 80 characters
  4. EXIF Title field
  5. EXIF ImageDescription field but only if less than 80 characters

The (2#nnn) value shown after each IPTC field (above) is the key of the array returned by PHP's iptcparse function for that particular IPTC field.

Change Log

Since: 2.5

Source File

wp_read_image_metadata() is located in wp-admin/includes/image.php