Make WordPress Core


Ignore:
Timestamp:
08/05/2024 04:11:40 AM (2 years ago)
Author:
noisysocks
Message:

Media: Automatically convert HEIC images to JPEG

Automatically create a JPEG version of uploaded HEIC images if the server has
a version of Imagick that supports HEIC. Conversion is done silently through
the existing WP_Image_Editor infrastructure that creates multiple sizes of
uploaded images.

This allows users to view HEIC images in WP Admin and use them in their posts
and pages regardless of whether their browser supports HEIC. Browser support
for HEIC is relatively low (only Safari) while the occurrence of HEIC images is
relatively common. The original HEIC image can be downloaded via a link on
the attachment page.

Props adamsilverstein, noisysocks, swissspidy, spacedmonkey, peterwilsoncc.
Fixes #53645.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/functions.php

    r58848 r58849  
    27072707                 */
    27082708                if ( $is_image ) {
    2709                         /** This filter is documented in wp-includes/class-wp-image-editor.php */
    2710                         $output_formats = apply_filters( 'image_editor_output_format', array(), $_dir . $filename, $mime_type );
     2709                        $output_formats = wp_get_image_editor_output_format( $_dir . $filename, $mime_type );
    27112710                        $alt_types      = array();
    27122711
    … …  
    31213120                                        'image/webp' => 'webp',
    31223121                                        'image/avif' => 'avif',
     3122                                        'image/heic' => 'heic',
    31233123                                )
    31243124                        );
    … …  
    33003300 * @since 5.8.0 Added support for WebP images.
    33013301 * @since 6.5.0 Added support for AVIF images.
     3302 * @since 6.7.0 Added support for HEIC images.
    33023303 *
    33033304 * @param string $file Full path to the file.
    … …  
    33723373                ) {
    33733374                        $mime = 'image/avif';
     3375                }
     3376
     3377                if (
     3378                        isset( $magic[1] ) &&
     3379                        isset( $magic[2] ) &&
     3380                        'ftyp' === hex2bin( $magic[1] ) &&
     3381                        ( 'heic' === hex2bin( $magic[2] ) || 'heif' === hex2bin( $magic[2] ) )
     3382                ) {
     3383                        $mime = 'image/heic';
    33743384                }
    33753385        } catch ( Exception $e ) {
Note: See TracChangeset for help on using the changeset viewer.