wp_read_image_metadata( string $file ): array|false
- Since
- 2.5.0
- Source
wp-admin/includes/image.php:825
Description
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, alt, and title. Also includes FNumber, Model, DateTimeDigitized, FocalLength, ISOSpeedRatings, and ExposureTime.
Compatibility
- WordPress
- since 2.5.0
- PHP
- 7.4–8.6-dev
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.
Parameters
$filestring
Return value
array|false- Image metadata array on success, false on failure.
Performance profile
How much work a call to wp_read_image_metadata() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.
- Cost class
- Heavy
- Scaling
- Scales with input
- Instructions
- 56–151
- Plugin surface
- 2 hooks
- Called by
- 4
Reads or writes the filesystem via file_exists().
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 410.
Third-party callbacks on 'wp_read_image_metadata_types', 'wp_read_image_metadata' run inside this call, and their cost is not bounded by anything here.
4 places in core call this, so the cost is paid more often than your own code shows.
What it touches
- hookthird-party callbacks
apply_filters()called directly - filesystemfilesystem access
file_exists()called directly
Further down the call graph this can also reach option, cache, serialize, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 11 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_read_image_metadata() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
file_exists() && $image_size !== false && empty($info) | 56–61 | file_exists(), wp_getimagesize(), wp_getimagesize(), wp_get_image_alttext(), apply_filters(), is_callable(), wp_kses_post_deep(), apply_filters() |
file_exists() && $image_size !== false && empty($info) && is_callable() && $image_type && !defined('WP_DEBUG') && is_array($exif) && empty($exif) && empty($value) && !empty($meta) | 99–130 | file_exists(), wp_getimagesize(), wp_getimagesize(), wp_get_image_alttext(), apply_filters(), is_callable(), exif_read_data(), wp_kses_post_deep(), apply_filters() |
file_exists() && $image_size !== false && empty($info) && is_callable() && $image_type && !defined('WP_DEBUG') && is_array($exif) && empty($value) | 108–130 | file_exists(), wp_getimagesize(), wp_getimagesize(), wp_get_image_alttext(), apply_filters(), is_callable(), exif_read_data(), wp_exif_date2ts(), wp_kses_post_deep(), apply_filters() |
file_exists() && $image_size !== false && empty($info) && is_callable() && $image_type && !defined('WP_DEBUG') && is_array($exif) && empty($value) && !empty($meta) | 114–138 | file_exists(), wp_getimagesize(), wp_getimagesize(), wp_get_image_alttext(), apply_filters(), is_callable(), exif_read_data(), wp_exif_frac2dec(), wp_kses_post_deep(), apply_filters() |
file_exists() && $image_size !== false && empty($info) && is_callable() && $image_type && !defined('WP_DEBUG') && is_array($exif) && empty($value) && !empty($meta) | 114–135 | file_exists(), wp_getimagesize(), wp_getimagesize(), wp_get_image_alttext(), apply_filters(), is_callable(), exif_read_data(), reset(), wp_kses_post_deep(), apply_filters() |
file_exists() && $image_size !== false && empty($info) && is_callable() && $image_type && !defined('WP_DEBUG') && is_array($exif) && empty($value) | 123–138 | file_exists(), wp_getimagesize(), wp_getimagesize(), wp_get_image_alttext(), apply_filters(), is_callable(), exif_read_data(), wp_exif_date2ts(), wp_exif_frac2dec(), wp_kses_post_deep(), apply_filters() |
file_exists() && $image_size !== false && empty($info) && is_callable() && $image_type && !defined('WP_DEBUG') && is_array($exif) && empty($value) | 123–132 | file_exists(), wp_getimagesize(), wp_getimagesize(), wp_get_image_alttext(), apply_filters(), is_callable(), exif_read_data(), wp_exif_date2ts(), reset(), wp_kses_post_deep(), apply_filters() |
file_exists() && $image_size !== false && empty($info) && is_callable() && $image_type && !defined('WP_DEBUG') && is_array($exif) && empty($value) && !empty($meta) | 129–143 | file_exists(), wp_getimagesize(), wp_getimagesize(), wp_get_image_alttext(), apply_filters(), is_callable(), exif_read_data(), reset(), wp_exif_frac2dec(), wp_kses_post_deep(), apply_filters() |
file_exists() && $image_size !== false && empty($info) && is_callable() && $image_type && !defined('WP_DEBUG') && is_array($exif) && empty($value) && !empty($meta) | 129–146 | file_exists(), wp_getimagesize(), wp_getimagesize(), wp_get_image_alttext(), apply_filters(), is_callable(), exif_read_data(), wp_exif_frac2dec(), wp_exif_frac2dec(), wp_kses_post_deep(), apply_filters() |
file_exists() && $image_size !== false && empty($info) && is_callable() && $image_type && !defined('WP_DEBUG') && is_array($exif) && empty($value) && !empty($meta) | 129–143 | file_exists(), wp_getimagesize(), wp_getimagesize(), wp_get_image_alttext(), apply_filters(), is_callable(), exif_read_data(), wp_exif_frac2dec(), reset(), wp_kses_post_deep(), apply_filters() |
file_exists() && $image_size !== false && empty($info) && is_callable() && $image_type && !defined('WP_DEBUG') && is_array($exif) && empty($value) && !empty($meta) | 144–151 | file_exists(), wp_getimagesize(), wp_getimagesize(), wp_get_image_alttext(), apply_filters(), is_callable(), exif_read_data(), wp_exif_frac2dec(), reset(), wp_exif_frac2dec(), wp_kses_post_deep(), apply_filters() |
This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 409 | 56–150 | 67 | 1 fewer instruction than PHP 8.5 |
| 8.5 | 410 | 56–151 | 67 | |
| 8.4 | 410 | 56–151 | 67 | 36 fewer instructions than PHP 8.3 |
| 8.3 | 446 | 56–156 | 67 | |
| 8.2 | 446 | 56–156 | 67 | 1 fewer instruction than PHP 8.1 |
| 8.1 | 447 | 57–157 | 67 | 7 fewer instructions than PHP 7.4 |
| 7.4 | 454 | 57–161 | 67 |
An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.
Hooks and filters fired · 2
2 hooks fire while wp_read_image_metadata() runs, in this order:
- apply_filters( wp_read_image_metadata_types )filterline 942 (+117 into the body)
Filters the image types to check for exif data.
- apply_filters( wp_read_image_metadata )filterline 1077 (+252 into the body)
Filters the array of meta data read from an image's exif data.
Uses · 10
- wp_getimagesize()Allows PHP's getimagesize() to be debuggable when necessary.
- mbstring_binary_safe_encoding()Sets the mbstring internal encoding to a binary safe encoding when func_overload is enabled.
- reset_mbstring_encoding()Resets the mbstring internal encoding to a users previously set encoding.
- wp_get_image_alttext()Gets the alt text from image meta data.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- wp_exif_frac2dec()Converts a fraction string to a decimal.
- wp_exif_date2ts()Converts the exif date format to a unix timestamp.
- wp_is_valid_utf8()Determines if a given byte string represents a valid UTF-8 encoding.
- utf8_encode()Converts a string from ISO-8859-1 to UTF-8.
- wp_kses_post_deep()Navigates through an array, object, or scalar, and sanitizes content for allowed HTML tags for post content.
Used by · 4
- WP_REST_Attachments_Controller::insert_attachment()Inserts the attachment post in the database. Does not update the attachment meta.
- media_handle_sideload()Handles a side-loaded file in the same way as an uploaded file is handled by media_handle_upload().
- media_handle_upload()Saves a file submitted from a POST request and create an attachment post for it.
- wp_create_image_subsizes()Creates image sub-sizes, adds the new data to the image meta `sizes` array, and updates the image metadata.
Changelog
Introduced in 2.5.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-admin/includes/image.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.