Helper to get full size dimensions

This commit is contained in:
Mike Jolley 2019-02-22 12:10:28 +00:00
parent 4a383fa832
commit d31fbb5bf3
1 changed files with 24 additions and 0 deletions

View File

@ -234,6 +234,30 @@ class WC_Regenerate_Images {
return $image; return $image;
} }
/**
* Get full size image dimensions.
*
* @param int $attachment_id Attachment ID of image.
* @return array Width and height. Empty array if the dimensions cannot be found.
*/
private static function get_full_size_image_dimensions( $attachment_id ) {
$imagedata = wp_get_attachment_metadata( $attachment_id );
if ( ! $imagedata ) {
return array();
}
if ( ! isset( $imagedata['file'] ) && isset( $imagedata['sizes']['full'] ) ) {
$imagedata['height'] = $imagedata['sizes']['full']['height'];
$imagedata['width'] = $imagedata['sizes']['full']['width'];
}
return array(
'width' => $imagedata['width'],
'height' => $imagedata['height'],
);
}
/** /**
* Ensure we are dealing with the correct image attachment * Ensure we are dealing with the correct image attachment
* *