<!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>[52837] trunk: Media: Store attachment's file size in metadata.</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/52837">52837</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/52837","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>spacedmonkey</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2022-03-10 13:08:19 +0000 (Thu, 10 Mar 2022)</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: Store attachment's file size in metadata. 

Store the file size of all newly uploaded attachments, as part of the metadata stored in post meta. Storing file size means, developers will not have to resort to doing `filesize` function calls, that can be time consuming on assets on offloaded to services like Amazon's S3. 

This change also introduces a new helper function called, `wp_filesize`. This is a wrapper around the `filesize` php function, that adds some helpful filters and ensures the return value is an integer.

Props Cybr, Spacedmonkey, SergeyBiryukov, johnwatkins0, swissspidy, desrosj, joemcgill, azaozz, antpb, adamsilverstein, uday17035. 
Fixes <a href="https://core.trac.wordpress.org/ticket/49412">#49412</a>. </pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpadminincludesfilephp">trunk/src/wp-admin/includes/file.php</a></li>
<li><a href="#trunksrcwpadminincludesimagephp">trunk/src/wp-admin/includes/image.php</a></li>
<li><a href="#trunksrcwpadminincludesmediaphp">trunk/src/wp-admin/includes/media.php</a></li>
<li><a href="#trunksrcwpincludesclasswpimageeditorgdphp">trunk/src/wp-includes/class-wp-image-editor-gd.php</a></li>
<li><a href="#trunksrcwpincludesclasswpimageeditorimagickphp">trunk/src/wp-includes/class-wp-image-editor-imagick.php</a></li>
<li><a href="#trunksrcwpincludesmediaphp">trunk/src/wp-includes/media.php</a></li>
<li><a href="#trunksrcwpincludespostphp">trunk/src/wp-includes/post.php</a></li>
<li><a href="#trunktestsphpunittestsfilephp">trunk/tests/phpunit/tests/file.php</a></li>
<li><a href="#trunktestsphpunittestsimageeditorGdphp">trunk/tests/phpunit/tests/image/editorGd.php</a></li>
<li><a href="#trunktestsphpunittestsimageeditorImagickphp">trunk/tests/phpunit/tests/image/editorImagick.php</a></li>
<li><a href="#trunktestsphpunittestsimagefunctionsphp">trunk/tests/phpunit/tests/image/functions.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpadminincludesfilephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/file.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/file.php      2022-03-10 10:56:09 UTC (rev 52836)
+++ trunk/src/wp-admin/includes/file.php        2022-03-10 13:08:19 UTC (rev 52837)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -2555,3 +2555,41 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</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">+
+/**
+ * Wrapper for PHP filesize with filters and casting the result as an integer.
+ *
+ * @since 6.0.0
+ *
+ * @link https://www.php.net/manual/en/function.filesize.php
+ *
+ * @param string $path Path to the file.
+ * @return int The size of the file in bytes, or 0 in the event of an error.
+ */
+function wp_filesize( $path ) {
+       /**
+        * Filters the result of wp_filesize before the PHP function is run.
+        *
+        * @since 6.0.0
+        *
+        * @param null|int $size The unfiltered value. Returning an int from the callback bypasses the filesize call.
+        * @param string   $path Path to the file.
+        */
+       $size = apply_filters( 'pre_wp_filesize', null, $path );
+
+       if ( is_int( $size ) ) {
+               return $size;
+       }
+
+       $size = (int) @filesize( $path );
+
+       /**
+        * Filters the size of the file.
+        *
+        * @since 6.0.0
+        *
+        * @param int    $size The result of PHP filesize on the file.
+        * @param string $path Path to the file.
+        */
+       return (int) apply_filters( 'wp_filesize', $size, $path );
+}
</ins></span></pre></div>
<a id="trunksrcwpadminincludesimagephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/image.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/image.php     2022-03-10 10:56:09 UTC (rev 52836)
+++ trunk/src/wp-admin/includes/image.php       2022-03-10 13:08:19 UTC (rev 52837)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -210,6 +210,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">        // Store the original image file name in image_meta.
</span><span class="cx" style="display: block; padding: 0 10px">        $image_meta['original_image'] = wp_basename( $original_file );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        // Add image file size.
+       $image_meta['filesize'] = wp_filesize( $new_file );
+
</ins><span class="cx" style="display: block; padding: 0 10px">         return $image_meta;
</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">@@ -235,10 +238,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        // Default image meta.
</span><span class="cx" style="display: block; padding: 0 10px">        $image_meta = array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                'width'  => $imagesize[0],
-               'height' => $imagesize[1],
-               'file'   => _wp_relative_upload_path( $file ),
-               'sizes'  => array(),
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         'width'    => $imagesize[0],
+               'height'   => $imagesize[1],
+               'file'     => _wp_relative_upload_path( $file ),
+               'filesize' => wp_filesize( $file ),
+               'sizes'    => array(),
</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">        // Fetch additional metadata from EXIF/IPTC.
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -629,6 +633,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">        // Remove the blob of binary data from the array.
</span><span class="cx" style="display: block; padding: 0 10px">        unset( $metadata['image']['data'] );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        // Capture file size for cases where it has not been captured yet, such as PDFs.
+       if ( ! isset( $metadata['filesize'] ) && file_exists( $file ) ) {
+               $metadata['filesize'] = wp_filesize( $file );
+       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">         /**
</span><span class="cx" style="display: block; padding: 0 10px">         * Filters the generated attachment meta data.
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span></span></pre></div>
<a id="trunksrcwpadminincludesmediaphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-admin/includes/media.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-admin/includes/media.php     2022-03-10 10:56:09 UTC (rev 52836)
+++ trunk/src/wp-admin/includes/media.php       2022-03-10 13:08:19 UTC (rev 52837)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -3378,7 +3378,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">        if ( isset( $meta['filesize'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                $file_size = $meta['filesize'];
</span><span class="cx" style="display: block; padding: 0 10px">        } elseif ( file_exists( $file ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $file_size = filesize( $file );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $file_size = wp_filesize( $file );
</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">        if ( ! empty( $file_size ) ) {
</span></span></pre></div>
<a id="trunksrcwpincludesclasswpimageeditorgdphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-image-editor-gd.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-image-editor-gd.php        2022-03-10 10:56:09 UTC (rev 52836)
+++ trunk/src/wp-includes/class-wp-image-editor-gd.php  2022-03-10 13:08:19 UTC (rev 52837)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -497,6 +497,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'width'     => $this->size['width'],
</span><span class="cx" style="display: block; padding: 0 10px">                        'height'    => $this->size['height'],
</span><span class="cx" style="display: block; padding: 0 10px">                        'mime-type' => $mime_type,
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        'filesize'  => wp_filesize( $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"> 
</span></span></pre></div>
<a id="trunksrcwpincludesclasswpimageeditorimagickphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/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">--- trunk/src/wp-includes/class-wp-image-editor-imagick.php   2022-03-10 10:56:09 UTC (rev 52836)
+++ trunk/src/wp-includes/class-wp-image-editor-imagick.php     2022-03-10 13:08:19 UTC (rev 52837)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -729,6 +729,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        'width'     => $this->size['width'],
</span><span class="cx" style="display: block; padding: 0 10px">                        'height'    => $this->size['height'],
</span><span class="cx" style="display: block; padding: 0 10px">                        'mime-type' => $mime_type,
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        'filesize'  => wp_filesize( $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"> 
</span></span></pre></div>
<a id="trunksrcwpincludesmediaphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/media.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/media.php   2022-03-10 10:56:09 UTC (rev 52836)
+++ trunk/src/wp-includes/media.php     2022-03-10 13:08:19 UTC (rev 52837)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -4046,7 +4046,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">        if ( isset( $meta['filesize'] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                $bytes = $meta['filesize'];
</span><span class="cx" style="display: block; padding: 0 10px">        } elseif ( file_exists( $attached_file ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $bytes = filesize( $attached_file );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $bytes = wp_filesize( $attached_file );
</ins><span class="cx" style="display: block; padding: 0 10px">         } else {
</span><span class="cx" style="display: block; padding: 0 10px">                $bytes = '';
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span></span></pre></div>
<a id="trunksrcwpincludespostphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/post.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/post.php    2022-03-10 10:56:09 UTC (rev 52836)
+++ trunk/src/wp-includes/post.php      2022-03-10 13:08:19 UTC (rev 52837)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -6538,6 +6538,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">  *     @type array  $sizes      Keys are size slugs, each value is an array containing
</span><span class="cx" style="display: block; padding: 0 10px">  *                              'file', 'width', 'height', and 'mime-type'.
</span><span class="cx" style="display: block; padding: 0 10px">  *     @type array  $image_meta Image metadata.
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ *     @type int    $filesize   File size of the attachment.
</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"> function wp_get_attachment_metadata( $attachment_id = 0, $unfiltered = false ) {
</span></span></pre></div>
<a id="trunktestsphpunittestsfilephp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/file.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/file.php        2022-03-10 10:56:09 UTC (rev 52836)
+++ trunk/tests/phpunit/tests/file.php  2022-03-10 13:08:19 UTC (rev 52837)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -262,4 +262,39 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                return $keys;
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+       /**
+        * @ticket 49412
+        * @covers ::wp_filesize
+        */
+       function test_wp_filesize_with_nonexistent_file() {
+               $file = 'nonexistent/file.jpg';
+               $this->assertEquals( 0, wp_filesize( $file ) );
+       }
+
+       /**
+        * @ticket 49412
+        * @covers ::wp_filesize
+        */
+       function test_wp_filesize() {
+               $file = DIR_TESTDATA . '/images/test-image-upside-down.jpg';
+
+               $this->assertEquals( filesize( $file ), wp_filesize( $file ) );
+
+               $filter = function() {
+                       return 999;
+               };
+
+               add_filter( 'wp_filesize', $filter );
+
+               $this->assertEquals( 999, wp_filesize( $file ) );
+
+               $pre_filter = function() {
+                       return 111;
+               };
+
+               add_filter( 'pre_wp_filesize', $pre_filter );
+
+               $this->assertEquals( 111, wp_filesize( $file ) );
+       }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunktestsphpunittestsimageeditorGdphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/image/editorGd.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/image/editorGd.php      2022-03-10 10:56:09 UTC (rev 52836)
+++ trunk/tests/phpunit/tests/image/editorGd.php        2022-03-10 13:08:19 UTC (rev 52837)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -100,6 +100,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'width'     => 50,
</span><span class="cx" style="display: block; padding: 0 10px">                                'height'    => 33,
</span><span class="cx" style="display: block; padding: 0 10px">                                'mime-type' => 'image/jpeg',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-50x33.jpg' ),
</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">@@ -300,6 +301,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'width'     => 10,
</span><span class="cx" style="display: block; padding: 0 10px">                                'height'    => 7,
</span><span class="cx" style="display: block; padding: 0 10px">                                'mime-type' => 'image/jpeg',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-10x7.jpg' ),
</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">                        // #1
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -308,6 +310,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'width'     => 75,
</span><span class="cx" style="display: block; padding: 0 10px">                                'height'    => 50,
</span><span class="cx" style="display: block; padding: 0 10px">                                'mime-type' => 'image/jpeg',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-75x50.jpg' ),
</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">                        // #2
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -316,6 +319,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'width'     => 30,
</span><span class="cx" style="display: block; padding: 0 10px">                                'height'    => 20,
</span><span class="cx" style="display: block; padding: 0 10px">                                'mime-type' => 'image/jpeg',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-30x20.jpg' ),
</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">                        // #3
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -324,6 +328,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'width'     => 45,
</span><span class="cx" style="display: block; padding: 0 10px">                                'height'    => 400,
</span><span class="cx" style="display: block; padding: 0 10px">                                'mime-type' => 'image/jpeg',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-45x400.jpg' ),
</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">                        // #4
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -332,6 +337,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'width'     => 50,
</span><span class="cx" style="display: block; padding: 0 10px">                                'height'    => 33,
</span><span class="cx" style="display: block; padding: 0 10px">                                'mime-type' => 'image/jpeg',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-50x33.jpg' ),
</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">                        // #5
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -340,6 +346,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'width'     => 55,
</span><span class="cx" style="display: block; padding: 0 10px">                                'height'    => 37,
</span><span class="cx" style="display: block; padding: 0 10px">                                'mime-type' => 'image/jpeg',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-55x37.jpg' ),
</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">                        // #6
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -348,6 +355,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'width'     => 83,
</span><span class="cx" style="display: block; padding: 0 10px">                                'height'    => 55,
</span><span class="cx" style="display: block; padding: 0 10px">                                'mime-type' => 'image/jpeg',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-83x55.jpg' ),
</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">                        // #7
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -356,6 +364,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'width'     => 90,
</span><span class="cx" style="display: block; padding: 0 10px">                                'height'    => 60,
</span><span class="cx" style="display: block; padding: 0 10px">                                'mime-type' => 'image/jpeg',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-90x60.jpg' ),
</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">                        // #8
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -364,6 +373,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'width'     => 105,
</span><span class="cx" style="display: block; padding: 0 10px">                                'height'    => 70,
</span><span class="cx" style="display: block; padding: 0 10px">                                'mime-type' => 'image/jpeg',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-105x70.jpg' ),
</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">                        // #9
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -372,6 +382,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'width'     => 200,
</span><span class="cx" style="display: block; padding: 0 10px">                                'height'    => 133,
</span><span class="cx" style="display: block; padding: 0 10px">                                'mime-type' => 'image/jpeg',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-200x133.jpg' ),
</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></pre></div>
<a id="trunktestsphpunittestsimageeditorImagickphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/image/editorImagick.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/image/editorImagick.php 2022-03-10 10:56:09 UTC (rev 52836)
+++ trunk/tests/phpunit/tests/image/editorImagick.php   2022-03-10 13:08:19 UTC (rev 52837)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -90,6 +90,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'width'     => 50,
</span><span class="cx" style="display: block; padding: 0 10px">                                'height'    => 33,
</span><span class="cx" style="display: block; padding: 0 10px">                                'mime-type' => 'image/jpeg',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-50x33.jpg' ),
</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">@@ -289,6 +290,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'width'     => 10,
</span><span class="cx" style="display: block; padding: 0 10px">                                'height'    => 7,
</span><span class="cx" style="display: block; padding: 0 10px">                                'mime-type' => 'image/jpeg',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-10x7.jpg' ),
</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">                        // #1
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -297,6 +299,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'width'     => 75,
</span><span class="cx" style="display: block; padding: 0 10px">                                'height'    => 50,
</span><span class="cx" style="display: block; padding: 0 10px">                                'mime-type' => 'image/jpeg',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-75x50.jpg' ),
</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">                        // #2
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -305,6 +308,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'width'     => 30,
</span><span class="cx" style="display: block; padding: 0 10px">                                'height'    => 20,
</span><span class="cx" style="display: block; padding: 0 10px">                                'mime-type' => 'image/jpeg',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-30x20.jpg' ),
</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">                        // #3
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -313,6 +317,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'width'     => 45,
</span><span class="cx" style="display: block; padding: 0 10px">                                'height'    => 400,
</span><span class="cx" style="display: block; padding: 0 10px">                                'mime-type' => 'image/jpeg',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-45x400.jpg' ),
</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">                        // #4
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -321,6 +326,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'width'     => 50,
</span><span class="cx" style="display: block; padding: 0 10px">                                'height'    => 33,
</span><span class="cx" style="display: block; padding: 0 10px">                                'mime-type' => 'image/jpeg',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-50x33.jpg' ),
</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">                        // #5
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -329,6 +335,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'width'     => 55,
</span><span class="cx" style="display: block; padding: 0 10px">                                'height'    => 37,
</span><span class="cx" style="display: block; padding: 0 10px">                                'mime-type' => 'image/jpeg',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-55x37.jpg' ),
</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">                        // #6
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -337,6 +344,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'width'     => 83,
</span><span class="cx" style="display: block; padding: 0 10px">                                'height'    => 55,
</span><span class="cx" style="display: block; padding: 0 10px">                                'mime-type' => 'image/jpeg',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-83x55.jpg' ),
</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">                        // #7
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -345,6 +353,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'width'     => 90,
</span><span class="cx" style="display: block; padding: 0 10px">                                'height'    => 60,
</span><span class="cx" style="display: block; padding: 0 10px">                                'mime-type' => 'image/jpeg',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-90x60.jpg' ),
</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">                        // #8
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -353,6 +362,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'width'     => 105,
</span><span class="cx" style="display: block; padding: 0 10px">                                'height'    => 70,
</span><span class="cx" style="display: block; padding: 0 10px">                                'mime-type' => 'image/jpeg',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-105x70.jpg' ),
</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">                        // #9
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -361,6 +371,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                'width'     => 200,
</span><span class="cx" style="display: block; padding: 0 10px">                                'height'    => 133,
</span><span class="cx" style="display: block; padding: 0 10px">                                'mime-type' => 'image/jpeg',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                'filesize'  => wp_filesize( dirname( $file ) . '/waffles-200x133.jpg' ),
</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></pre></div>
<a id="trunktestsphpunittestsimagefunctionsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/image/functions.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/image/functions.php     2022-03-10 10:56:09 UTC (rev 52836)
+++ trunk/tests/phpunit/tests/image/functions.php       2022-03-10 13:08:19 UTC (rev 52837)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -479,13 +479,18 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertNotEmpty( $attachment_id );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $temp_dir = get_temp_dir();
+
+               $metadata = wp_generate_attachment_metadata( $attachment_id, $test_file );
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 $expected = array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'sizes' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'sizes'    => array(
</ins><span class="cx" style="display: block; padding: 0 10px">                                 'full'      => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                        'file'      => 'wordpress-gsoc-flyer-pdf.jpg',
</span><span class="cx" style="display: block; padding: 0 10px">                                        'width'     => 1088,
</span><span class="cx" style="display: block; padding: 0 10px">                                        'height'    => 1408,
</span><span class="cx" style="display: block; padding: 0 10px">                                        'mime-type' => 'image/jpeg',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                        'filesize'  => wp_filesize( $temp_dir . 'wordpress-gsoc-flyer-pdf.jpg' ),
</ins><span class="cx" style="display: block; padding: 0 10px">                                 ),
</span><span class="cx" style="display: block; padding: 0 10px">                                'medium'    => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                        'file'      => 'wordpress-gsoc-flyer-pdf-232x300.jpg',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -492,6 +497,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                        'width'     => 232,
</span><span class="cx" style="display: block; padding: 0 10px">                                        'height'    => 300,
</span><span class="cx" style="display: block; padding: 0 10px">                                        'mime-type' => 'image/jpeg',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                        'filesize'  => wp_filesize( $temp_dir . 'wordpress-gsoc-flyer-pdf-232x300.jpg' ),
</ins><span class="cx" style="display: block; padding: 0 10px">                                 ),
</span><span class="cx" style="display: block; padding: 0 10px">                                'large'     => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                        'file'      => 'wordpress-gsoc-flyer-pdf-791x1024.jpg',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -498,6 +504,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                        'width'     => 791,
</span><span class="cx" style="display: block; padding: 0 10px">                                        'height'    => 1024,
</span><span class="cx" style="display: block; padding: 0 10px">                                        'mime-type' => 'image/jpeg',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                        'filesize'  => wp_filesize( $temp_dir . 'wordpress-gsoc-flyer-pdf-791x1024.jpg' ),
</ins><span class="cx" style="display: block; padding: 0 10px">                                 ),
</span><span class="cx" style="display: block; padding: 0 10px">                                'thumbnail' => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                        'file'      => 'wordpress-gsoc-flyer-pdf-116x150.jpg',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -504,15 +511,15 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                        'width'     => 116,
</span><span class="cx" style="display: block; padding: 0 10px">                                        'height'    => 150,
</span><span class="cx" style="display: block; padding: 0 10px">                                        'mime-type' => 'image/jpeg',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                        'filesize'  => wp_filesize( $temp_dir . 'wordpress-gsoc-flyer-pdf-116x150.jpg' ),
</ins><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">+                        'filesize' => wp_filesize( $test_file ),
</ins><span class="cx" style="display: block; padding: 0 10px">                 );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $metadata = wp_generate_attachment_metadata( $attachment_id, $test_file );
</del><span class="cx" style="display: block; padding: 0 10px">                 $this->assertSame( $expected, $metadata );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                unlink( $test_file );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $temp_dir = get_temp_dir();
</del><span class="cx" style="display: block; padding: 0 10px">                 foreach ( $metadata['sizes'] as $size ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        unlink( $temp_dir . $size['file'] );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -549,13 +556,18 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertNotEmpty( $attachment_id );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $temp_dir = get_temp_dir();
+
+               $metadata = wp_generate_attachment_metadata( $attachment_id, $test_file );
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 $expected = array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        'sizes' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 'sizes'    => array(
</ins><span class="cx" style="display: block; padding: 0 10px">                                 'full'      => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                        'file'      => 'wordpress-gsoc-flyer-pdf.jpg',
</span><span class="cx" style="display: block; padding: 0 10px">                                        'width'     => 1088,
</span><span class="cx" style="display: block; padding: 0 10px">                                        'height'    => 1408,
</span><span class="cx" style="display: block; padding: 0 10px">                                        'mime-type' => 'image/jpeg',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                        'filesize'  => wp_filesize( $temp_dir . 'wordpress-gsoc-flyer-pdf.jpg' ),
</ins><span class="cx" style="display: block; padding: 0 10px">                                 ),
</span><span class="cx" style="display: block; padding: 0 10px">                                'medium'    => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                        'file'      => 'wordpress-gsoc-flyer-pdf-300x300.jpg',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -562,6 +574,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                        'width'     => 300,
</span><span class="cx" style="display: block; padding: 0 10px">                                        'height'    => 300,
</span><span class="cx" style="display: block; padding: 0 10px">                                        'mime-type' => 'image/jpeg',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                        'filesize'  => wp_filesize( $temp_dir . 'wordpress-gsoc-flyer-pdf-300x300.jpg' ),
</ins><span class="cx" style="display: block; padding: 0 10px">                                 ),
</span><span class="cx" style="display: block; padding: 0 10px">                                'large'     => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                        'file'      => 'wordpress-gsoc-flyer-pdf-791x1024.jpg',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -568,6 +581,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                        'width'     => 791,
</span><span class="cx" style="display: block; padding: 0 10px">                                        'height'    => 1024,
</span><span class="cx" style="display: block; padding: 0 10px">                                        'mime-type' => 'image/jpeg',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                        'filesize'  => wp_filesize( $temp_dir . 'wordpress-gsoc-flyer-pdf-791x1024.jpg' ),
</ins><span class="cx" style="display: block; padding: 0 10px">                                 ),
</span><span class="cx" style="display: block; padding: 0 10px">                                'thumbnail' => array(
</span><span class="cx" style="display: block; padding: 0 10px">                                        'file'      => 'wordpress-gsoc-flyer-pdf-116x150.jpg',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -574,16 +588,17 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                        'width'     => 116,
</span><span class="cx" style="display: block; padding: 0 10px">                                        'height'    => 150,
</span><span class="cx" style="display: block; padding: 0 10px">                                        'mime-type' => 'image/jpeg',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                        'filesize'  => wp_filesize( $temp_dir . 'wordpress-gsoc-flyer-pdf-116x150.jpg' ),
</ins><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">+                        'filesize' => wp_filesize( $test_file ),
</ins><span class="cx" style="display: block; padding: 0 10px">                 );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $metadata = wp_generate_attachment_metadata( $attachment_id, $test_file );
</del><span class="cx" style="display: block; padding: 0 10px">                 $this->assertSame( $expected, $metadata );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                unlink( $test_file );
</span><span class="cx" style="display: block; padding: 0 10px">                foreach ( $metadata['sizes'] as $size ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                        unlink( get_temp_dir() . $size['file'] );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                 unlink( $temp_dir . $size['file'] );
</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">@@ -617,14 +632,21 @@
</span><span class="cx" style="display: block; padding: 0 10px">                add_image_size( 'test-size', 100, 100 );
</span><span class="cx" style="display: block; padding: 0 10px">                add_filter( 'fallback_intermediate_image_sizes', array( $this, 'filter_fallback_intermediate_image_sizes' ), 10, 2 );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $metadata = wp_generate_attachment_metadata( $attachment_id, $test_file );
+
+               $temp_dir = get_temp_dir();
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 $expected = array(
</span><span class="cx" style="display: block; padding: 0 10px">                        'file'      => 'wordpress-gsoc-flyer-pdf-77x100.jpg',
</span><span class="cx" style="display: block; padding: 0 10px">                        'width'     => 77,
</span><span class="cx" style="display: block; padding: 0 10px">                        'height'    => 100,
</span><span class="cx" style="display: block; padding: 0 10px">                        'mime-type' => 'image/jpeg',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        'filesize'  => wp_filesize( $temp_dir . 'wordpress-gsoc-flyer-pdf-77x100.jpg' ),
</ins><span class="cx" style="display: block; padding: 0 10px">                 );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $metadata = wp_generate_attachment_metadata( $attachment_id, $test_file );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // Different environments produce slightly different filesize results.
+               $this->assertSame( $metadata['sizes']['test-size'], $expected );
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 $this->assertArrayHasKey( 'test-size', $metadata['sizes'], 'The `test-size` was not added to the metadata.' );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( $expected, $metadata['sizes']['test-size'] );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -632,7 +654,6 @@
</span><span class="cx" style="display: block; padding: 0 10px">                remove_filter( 'fallback_intermediate_image_sizes', array( $this, 'filter_fallback_intermediate_image_sizes' ), 10 );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                unlink( $test_file );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $temp_dir = get_temp_dir();
</del><span class="cx" style="display: block; padding: 0 10px">                 foreach ( $metadata['sizes'] as $size ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        unlink( $temp_dir . $size['file'] );
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span></span></pre>
</div>
</div>

</body>
</html>