Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass EXIF Data to the wp_read_image_metadata filter #904 #1020

Merged
merged 5 commits into from Aug 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/wp-admin/includes/image.php
Expand Up @@ -348,7 +348,7 @@ function wp_read_image_metadata( $file ) {
if ( ! file_exists( $file ) )
return false;

list( , , $sourceImageType ) = @getimagesize( $file );
list( , , $image_type ) = @getimagesize( $file );

/*
* EXIF contains a bunch of data we'll probably never need formatted in ways
Expand Down Expand Up @@ -425,14 +425,18 @@ function wp_read_image_metadata( $file ) {
}
}

$exif = array();

/**
* Filters the image types to check for exif data.
*
* @since WP-2.5.0
*
* @param array $image_types Image types to check for exif data.
*/
if ( is_callable( 'exif_read_data' ) && in_array( $sourceImageType, apply_filters( 'wp_read_image_metadata_types', array( IMAGETYPE_JPEG, IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM ) ) ) ) {
$exif_image_types = apply_filters( 'wp_read_image_metadata_types', array( IMAGETYPE_JPEG, IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM ) );

if ( is_callable( 'exif_read_data' ) && in_array( $image_type, $exif_image_types ) ) {
$exif = @exif_read_data( $file );

if ( ! empty( $exif['ImageDescription'] ) ) {
Expand Down Expand Up @@ -510,13 +514,15 @@ function wp_read_image_metadata( $file ) {
*
* @since WP-2.5.0
* @since WP-4.4.0 The `$iptc` parameter was added.
* @since WP-5.0.0 The `$exif` parameter was added.
*
* @param array $meta Image meta data.
* @param string $file Path to image file.
* @param int $sourceImageType Type of image.
* @param int $image_type Type of image, one of the `IMAGETYPE_XXX` constants.
* @param array $iptc IPTC data.
* @param array $exif EXIF data.
*/
return apply_filters( 'wp_read_image_metadata', $meta, $file, $sourceImageType, $iptc );
return apply_filters( 'wp_read_image_metadata', $meta, $file, $image_type, $iptc, $exif );

}

Expand Down