<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[59360] branches/6.7/src/wp-includes: Media: Fix uploading of .heic images.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/59360">59360</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/59360","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>peterwilsoncc</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2024-11-06 00:45:48 +0000 (Wed, 06 Nov 2024)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Media: Fix uploading of .heic images.

- Adds support for all HEIC/HEIF mime types: `image/heic`, `image/heif`, `image/heic-sequence`, and `image/heif-sequence`.
- Introduces `wp_is_heic_image_mime_type()`.

This backport includes a subsequent fix of a typo.

Reviewed by peterwilsoncc.
Merges [59315,59358] to the 6.7 branch.

Props swissspidy, adamsilverstein, debarghyabanerjee, ironprogrammer, peterwilsoncc, apermo, azaozz, mosne.
Fixes <a href="https://core.trac.wordpress.org/ticket/62272">#62272</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branches67srcjsmediacontrollerslibraryjs">branches/6.7/src/js/media/controllers/library.js</a></li>
<li><a href="#branches67srcwpincludesclasswpimageeditorimagickphp">branches/6.7/src/wp-includes/class-wp-image-editor-imagick.php</a></li>
<li><a href="#branches67srcwpincludesfunctionsphp">branches/6.7/src/wp-includes/functions.php</a></li>
<li><a href="#branches67srcwpincludesmediaphp">branches/6.7/src/wp-includes/media.php</a></li>
</ul>

<h3>Property Changed</h3>
<ul>
<li><a href="#branches67">branches/6.7/</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<span class="cx" style="display: block; padding: 0 10px">Index: branches/6.7
</span><span class="cx" style="display: block; padding: 0 10px">===================================================================
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">--- branches/6.7 2024-11-06 00:42:12 UTC (rev 59359)
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+++ branches/6.7  2024-11-06 00:45:48 UTC (rev 59360)
</ins><a id="branches67"></a>
<div class="propset"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Property changes: branches/6.7</h4>
<pre class="diff"><span>
</span></pre></div>
<a id="svnmergeinfo"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: svn:mergeinfo</h4></div>
<span class="cx" style="display: block; padding: 0 10px"> /branches/5.0:43681-43682,43684-43688,43719-43720,43723,43726-43727,43729-43731,43734-43744,43747,43751-43754,43758,43760-43765,43767-43770,43772,43774-43781,43783,43785,43790-43806,43808-43821,43825,43828,43830-43834,43836-43843,43846-43863,43867-43889,43891-43894,43897-43905,43908-43909,43911-43929,43931-43942,43946-43947,43949-43956,43959-43964,43967-43969,43988,43994,44014,44017,44047,44183,44185,44187-44206,44208-44213,44231-44232,44235,44248,44284,44287-44288
</span><span class="cx" style="display: block; padding: 0 10px"> /branches/5.5:49373-49379,49381
</span><span class="cx" style="display: block; padding: 0 10px"> /branches/5.8:51889
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-/trunk:58570,59279-59280,59283,59286,59289-59290,59293,59306-59307,59314,59316,59318-59319,59325-59326,59329-59330,59339,59341,59347-59348
</del><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+/trunk:58570,59279-59280,59283,59286,59289-59290,59293,59306-59307,59314-59316,59318-59319,59325-59326,59329-59330,59339,59341,59347-59348,59358
</ins><span class="cx" style="display: block; padding: 0 10px">\ No newline at end of property
</span><a id="branches67srcjsmediacontrollerslibraryjs"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/6.7/src/js/media/controllers/library.js</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/6.7/src/js/media/controllers/library.js  2024-11-06 00:42:12 UTC (rev 59359)
+++ branches/6.7/src/js/media/controllers/library.js    2024-11-06 00:45:48 UTC (rev 59360)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -196,7 +196,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">        isImageAttachment: function( attachment ) {
</span><span class="cx" style="display: block; padding: 0 10px">                // If uploading, we know the filename but not the mime type.
</span><span class="cx" style="display: block; padding: 0 10px">                if ( attachment.get('uploading') ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        return /\.(jpe?g|png|gif|webp|avif|heic)$/i.test( attachment.get('filename') );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 return /\.(jpe?g|png|gif|webp|avif|heic|heif)$/i.test( attachment.get('filename') );
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                return attachment.get('type') === 'image';
</span></span></pre></div>
<a id="branches67srcwpincludesclasswpimageeditorimagickphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/6.7/src/wp-includes/class-wp-image-editor-imagick.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/6.7/src/wp-includes/class-wp-image-editor-imagick.php    2024-11-06 00:42:12 UTC (rev 59359)
+++ branches/6.7/src/wp-includes/class-wp-image-editor-imagick.php      2024-11-06 00:45:48 UTC (rev 59360)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -271,7 +271,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                 * If we still don't have the image size, fall back to `wp_getimagesize`. This ensures AVIF and HEIC images
</span><span class="cx" style="display: block; padding: 0 10px">                 * are properly sized without affecting previous `getImageGeometry` behavior.
</span><span class="cx" style="display: block; padding: 0 10px">                 */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ( ! $width || ! $height ) && ( 'image/avif' === $this->mime_type || 'image/heic' === $this->mime_type ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( ( ! $width || ! $height ) && ( 'image/avif' === $this->mime_type || wp_is_heic_image_mime_type( $this->mime_type ) ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         $size   = wp_getimagesize( $this->file );
</span><span class="cx" style="display: block; padding: 0 10px">                        $width  = $size[0];
</span><span class="cx" style="display: block; padding: 0 10px">                        $height = $size[1];
</span></span></pre></div>
<a id="branches67srcwpincludesfunctionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/6.7/src/wp-includes/functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/6.7/src/wp-includes/functions.php        2024-11-06 00:42:12 UTC (rev 59359)
+++ branches/6.7/src/wp-includes/functions.php  2024-11-06 00:45:48 UTC (rev 59360)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3101,7 +3101,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // Attempt to figure out what type of image it actually is.
</span><span class="cx" style="display: block; padding: 0 10px">                $real_mime = wp_get_image_mime( $file );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( $real_mime && $real_mime !== $type ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $heic_images_extensions = array(
+                       'heif',
+                       'heics',
+                       'heifs',
+               );
+
+               if ( $real_mime && ( $real_mime !== $type || in_array( $ext, $heic_images_extensions, true ) ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         /**
</span><span class="cx" style="display: block; padding: 0 10px">                         * Filters the list mapping image mime types to their respective extensions.
</span><span class="cx" style="display: block; padding: 0 10px">                         *
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3119,7 +3125,17 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                        'image/tiff' => 'tif',
</span><span class="cx" style="display: block; padding: 0 10px">                                        'image/webp' => 'webp',
</span><span class="cx" style="display: block; padding: 0 10px">                                        'image/avif' => 'avif',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+                                       /*
+                                        * In theory there are/should be file extensions that correspond to the
+                                        * mime types: .heif, .heics and .heifs. However it seems that HEIC images
+                                        * with any of the mime types commonly have a .heic file extension.
+                                        * Seems keeping the status quo here is best for compatibility.
+                                        */
</ins><span class="cx" style="display: block; padding: 0 10px">                                         'image/heic' => 'heic',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                        'image/heif' => 'heic',
+                                       'image/heic-sequence' => 'heic',
+                                       'image/heif-sequence' => 'heic',
</ins><span class="cx" style="display: block; padding: 0 10px">                                 )
</span><span class="cx" style="display: block; padding: 0 10px">                        );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3126,6 +3142,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        // Replace whatever is after the last period in the filename with the correct extension.
</span><span class="cx" style="display: block; padding: 0 10px">                        if ( ! empty( $mime_to_ext[ $real_mime ] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                                $filename_parts = explode( '.', $filename );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px">                                 array_pop( $filename_parts );
</span><span class="cx" style="display: block; padding: 0 10px">                                $filename_parts[] = $mime_to_ext[ $real_mime ];
</span><span class="cx" style="display: block; padding: 0 10px">                                $new_filename     = implode( '.', $filename_parts );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3316,9 +3333,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $mime      = ( $imagetype ) ? image_type_to_mime_type( $imagetype ) : false;
</span><span class="cx" style="display: block; padding: 0 10px">                } elseif ( function_exists( 'getimagesize' ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        // Don't silence errors when in debug mode, unless running unit tests.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        if ( defined( 'WP_DEBUG' ) && WP_DEBUG
-                               && ! defined( 'WP_RUN_CORE_TESTS' )
-                       ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 if ( defined( 'WP_DEBUG' ) && WP_DEBUG && ! defined( 'WP_RUN_CORE_TESTS' ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                                 // Not using wp_getimagesize() here to avoid an infinite loop.
</span><span class="cx" style="display: block; padding: 0 10px">                                $imagesize = getimagesize( $file );
</span><span class="cx" style="display: block; padding: 0 10px">                        } else {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3365,22 +3380,28 @@
</span><span class="cx" style="display: block; padding: 0 10px">                // Divide the header string into 4 byte groups.
</span><span class="cx" style="display: block; padding: 0 10px">                $magic = str_split( $magic, 8 );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if (
-                       isset( $magic[1] ) &&
-                       isset( $magic[2] ) &&
-                       'ftyp' === hex2bin( $magic[1] ) &&
-                       ( 'avif' === hex2bin( $magic[2] ) || 'avis' === hex2bin( $magic[2] ) )
-               ) {
-                       $mime = 'image/avif';
-               }
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         if ( isset( $magic[1] ) && isset( $magic[2] ) && 'ftyp' === hex2bin( $magic[1] ) ) {
+                       if ( 'avif' === hex2bin( $magic[2] ) || 'avis' === hex2bin( $magic[2] ) ) {
+                               $mime = 'image/avif';
+                       } elseif ( 'heic' === hex2bin( $magic[2] ) ) {
+                               $mime = 'image/heic';
+                       } elseif ( 'heif' === hex2bin( $magic[2] ) ) {
+                               $mime = 'image/heif';
+                       } else {
+                               /*
+                                * HEIC/HEIF images and image sequences/animations may have other strings here
+                                * like mif1, msf1, etc. For now fall back to using finfo_file() to detect these.
+                                */
+                               if ( extension_loaded( 'fileinfo' ) ) {
+                                       $fileinfo  = finfo_open( FILEINFO_MIME_TYPE );
+                                       $mime_type = finfo_file( $fileinfo, $file );
+                                       finfo_close( $fileinfo );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if (
-                       isset( $magic[1] ) &&
-                       isset( $magic[2] ) &&
-                       'ftyp' === hex2bin( $magic[1] ) &&
-                       ( 'heic' === hex2bin( $magic[2] ) || 'heif' === hex2bin( $magic[2] ) )
-               ) {
-                       $mime = 'image/heic';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 if ( wp_is_heic_image_mime_type( $mime_type ) ) {
+                                               $mime = $mime_type;
+                                       }
+                               }
+                       }
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px">        } catch ( Exception $e ) {
</span><span class="cx" style="display: block; padding: 0 10px">                $mime = false;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3423,7 +3444,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'webp'                         => 'image/webp',
</span><span class="cx" style="display: block; padding: 0 10px">                        'avif'                         => 'image/avif',
</span><span class="cx" style="display: block; padding: 0 10px">                        'ico'                          => 'image/x-icon',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+                       // TODO: Needs improvement. All images with the following mime types seem to have .heic file extension.
</ins><span class="cx" style="display: block; padding: 0 10px">                         'heic'                         => 'image/heic',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        'heif'                         => 'image/heif',
+                       'heics'                        => 'image/heic-sequence',
+                       'heifs'                        => 'image/heif-sequence',
+
</ins><span class="cx" style="display: block; padding: 0 10px">                         // Video formats.
</span><span class="cx" style="display: block; padding: 0 10px">                        'asf|asx'                      => 'video/x-ms-asf',
</span><span class="cx" style="display: block; padding: 0 10px">                        'wmv'                          => 'video/x-ms-wmv',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3543,7 +3570,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">        return apply_filters(
</span><span class="cx" style="display: block; padding: 0 10px">                'ext2type',
</span><span class="cx" style="display: block; padding: 0 10px">                array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'image'       => array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico', 'heic', 'webp', 'avif' ),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'image'       => array( 'jpg', 'jpeg', 'jpe', 'gif', 'png', 'bmp', 'tif', 'tiff', 'ico', 'heic', 'heif', 'webp', 'avif' ),
</ins><span class="cx" style="display: block; padding: 0 10px">                         'audio'       => array( 'aac', 'ac3', 'aif', 'aiff', 'flac', 'm3a', 'm4a', 'm4b', 'mka', 'mp1', 'mp2', 'mp3', 'ogg', 'oga', 'ram', 'wav', 'wma' ),
</span><span class="cx" style="display: block; padding: 0 10px">                        'video'       => array( '3g2', '3gp', '3gpp', 'asf', 'avi', 'divx', 'dv', 'flv', 'm4v', 'mkv', 'mov', 'mp4', 'mpeg', 'mpg', 'mpv', 'ogm', 'ogv', 'qt', 'rm', 'vob', 'wmv' ),
</span><span class="cx" style="display: block; padding: 0 10px">                        'document'    => array( 'doc', 'docx', 'docm', 'dotm', 'odt', 'pages', 'pdf', 'xps', 'oxps', 'rtf', 'wp', 'wpd', 'psd', 'xcf' ),
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -9037,3 +9064,22 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        echo wp_kses_post( wp_get_admin_notice( $message, $args ) );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+/**
+ * Checks if a mime type is for a HEIC/HEIF image.
+ *
+ * @since 6.7.0
+ *
+ * @param string $mime_type The mime type to check.
+ * @return bool Whether the mime type is for a HEIC/HEIF image.
+ */
+function wp_is_heic_image_mime_type( $mime_type ) {
+       $heic_mime_types = array(
+               'image/heic',
+               'image/heif',
+               'image/heic-sequence',
+               'image/heif-sequence',
+       );
+
+       return in_array( $mime_type, $heic_mime_types, true );
+}
</ins></span></pre></div>
<a id="branches67srcwpincludesmediaphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: branches/6.7/src/wp-includes/media.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- branches/6.7/src/wp-includes/media.php    2024-11-06 00:42:12 UTC (rev 59359)
+++ branches/6.7/src/wp-includes/media.php      2024-11-06 00:45:48 UTC (rev 59360)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5627,9 +5627,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">  */
</span><span class="cx" style="display: block; padding: 0 10px"> function wp_getimagesize( $filename, ?array &$image_info = null ) {
</span><span class="cx" style="display: block; padding: 0 10px">        // Don't silence errors when in debug mode, unless running unit tests.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        if ( defined( 'WP_DEBUG' ) && WP_DEBUG
-               && ! defined( 'WP_RUN_CORE_TESTS' )
-       ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( defined( 'WP_DEBUG' ) && WP_DEBUG && ! defined( 'WP_RUN_CORE_TESTS' ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                 if ( 2 === func_num_args() ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $info = getimagesize( $filename, $image_info );
</span><span class="cx" style="display: block; padding: 0 10px">                } else {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5660,11 +5658,18 @@
</span><span class="cx" style="display: block; padding: 0 10px">                return $info;
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        $image_mime_type = wp_get_image_mime( $filename );
+
+       // Not an image?
+       if ( false === $image_mime_type ) {
+               return false;
+       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">         /*
</span><span class="cx" style="display: block; padding: 0 10px">         * For PHP versions that don't support WebP images,
</span><span class="cx" style="display: block; padding: 0 10px">         * extract the image size info from the file headers.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        if ( 'image/webp' === wp_get_image_mime( $filename ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( 'image/webp' === $image_mime_type ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                 $webp_info = wp_get_webp_info( $filename );
</span><span class="cx" style="display: block; padding: 0 10px">                $width     = $webp_info['width'];
</span><span class="cx" style="display: block; padding: 0 10px">                $height    = $webp_info['height'];
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5686,7 +5691,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        // For PHP versions that don't support AVIF images, extract the image size info from the file headers.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        if ( 'image/avif' === wp_get_image_mime( $filename ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( 'image/avif' === $image_mime_type ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                 $avif_info = wp_get_avif_info( $filename );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $width  = $avif_info['width'];
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -5709,11 +5714,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        // For PHP versions that don't support HEIC images, extract the size info using Imagick when available.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        if ( 'image/heic' === wp_get_image_mime( $filename ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( wp_is_heic_image_mime_type( $image_mime_type ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                 $editor = wp_get_image_editor( $filename );
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px">                 if ( is_wp_error( $editor ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        return false;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px">                 // If the editor for HEICs is Imagick, use it to get the image size.
</span><span class="cx" style="display: block; padding: 0 10px">                if ( $editor instanceof WP_Image_Editor_Imagick ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $size = $editor->get_size();
</span></span></pre>
</div>
</div>

</body>
</html>