wpseek.com
A WordPress-centric search engine for devs and theme authors



wp_upload_image_mime_transforms › WordPress Function

Since6.1.0
Deprecatedn/a
wp_upload_image_mime_transforms ( $attachment_id )
Parameters:
  • (int) $attachment_id The attachment ID.
    Required: Yes
Returns:
  • (array) An array of valid mime types, where the key is the source file mime type and the list of mime types to generate.
Defined at:
Codex:

Returns an array with the list of valid mime types that a specific mime type should be converted into.

For example an image/jpeg should be converted into an image/jpeg and image/webp. The first type is considered the primary output type for this image. Called for each uploaded image to determine the list of mime types that should be converted into. Then, called again for each image size as they are generated to check if the image should be converted into the mime type for that size.


Source

function wp_upload_image_mime_transforms( $attachment_id ) {
	$default_image_mime_transforms = array(
		'image/jpeg' => array( 'image/jpeg', 'image/webp' ),
		'image/webp' => array( 'image/webp', 'image/jpeg' ),
	);
	$image_mime_transforms         = $default_image_mime_transforms;

	/**
	 * Filters the output mime types for a given input mime type and image size.
	 *
	 * @since 6.1.0
	 *
	 * @param array $image_mime_transforms A map with the valid mime transforms where the key is the source file mime type
	 *                                      and the value is one or more mime file types to generate.
	 * @param int   $attachment_id         The ID of the attachment where the hook was dispatched.
	 */
	$image_mime_transforms = apply_filters( 'wp_upload_image_mime_transforms', $image_mime_transforms, $attachment_id );

	if ( ! is_array( $image_mime_transforms ) ) {
		return $default_image_mime_transforms;
	}

	return array_map(
		function( $transforms_list ) {
			return (array) $transforms_list;
		},
		$image_mime_transforms
	);
}