Make WordPress Core

Ticket #49412: 49412.2.diff

File 49412.2.diff, 12.2 KB (added by johnwatkins0, 5 years ago)

Removed a line of debug code

  • src/wp-admin/includes/image.php

    diff --git a/src/wp-admin/includes/image.php b/src/wp-admin/includes/image.php
    index f9108091fc..959721cd45 100644
    a b function wp_create_image_subsizes( $file, $attachment_id ) { 
    233233
    234234        // Default image meta.
    235235        $image_meta = array(
    236                 'width'  => $imagesize[0],
    237                 'height' => $imagesize[1],
    238                 'file'   => _wp_relative_upload_path( $file ),
    239                 'sizes'  => array(),
     236                'width'    => $imagesize[0],
     237                'height'   => $imagesize[1],
     238                'file'     => _wp_relative_upload_path( $file ),
     239                'filesize' => filesize( $file ),
     240                'sizes'    => array(),
    240241        );
    241242
    242243        // Fetch additional metadata from EXIF/IPTC.
    function wp_generate_attachment_metadata( $attachment_id, $file ) { 
    611612                unset( $metadata['image']['data'] );
    612613        }
    613614
     615        // Capture file size for cases where it has not been captured yet, such as PDFs.
     616        if ( ! isset( $metadata['filesize'] ) && file_exists( $file ) ) {
     617                $metadata['filesize'] = filesize( $file );
     618        }
     619
    614620        /**
    615621         * Filters the generated attachment meta data.
    616622         *
  • src/wp-includes/class-wp-image-editor-gd.php

    diff --git a/src/wp-includes/class-wp-image-editor-gd.php b/src/wp-includes/class-wp-image-editor-gd.php
    index 51313d456d..45d711a221 100644
    a b class WP_Image_Editor_GD extends WP_Image_Editor { 
    463463                return array(
    464464                        'path'      => $filename,
    465465                        'file'      => wp_basename( apply_filters( 'image_make_intermediate_size', $filename ) ),
     466                        'filesize'  => filesize( $filename ),
    466467                        'width'     => $this->size['width'],
    467468                        'height'    => $this->size['height'],
    468469                        'mime-type' => $mime_type,
  • src/wp-includes/class-wp-image-editor-imagick.php

    diff --git a/src/wp-includes/class-wp-image-editor-imagick.php b/src/wp-includes/class-wp-image-editor-imagick.php
    index ea2c48eb4d..9967bac70b 100644
    a b class WP_Image_Editor_Imagick extends WP_Image_Editor { 
    696696                        'path'      => $filename,
    697697                        /** This filter is documented in wp-includes/class-wp-image-editor-gd.php */
    698698                        'file'      => wp_basename( apply_filters( 'image_make_intermediate_size', $filename ) ),
     699                        'filesize'  => filesize( $filename ),
    699700                        'width'     => $this->size['width'],
    700701                        'height'    => $this->size['height'],
    701702                        'mime-type' => $mime_type,
  • tests/phpunit/tests/image/editorGd.php

    diff --git a/tests/phpunit/tests/image/editorGd.php b/tests/phpunit/tests/image/editorGd.php
    index 0c9ddd650b..184720bc1e 100644
    a b class Tests_Image_Editor_GD extends WP_Image_UnitTestCase { 
    9595                                'width'     => 50,
    9696                                'height'    => 33,
    9797                                'mime-type' => 'image/jpeg',
     98                                'filesize'  => 1244,
    9899                        ),
    99100                );
    100101
    class Tests_Image_Editor_GD extends WP_Image_UnitTestCase { 
    294295                                'width'     => 10,
    295296                                'height'    => 7,
    296297                                'mime-type' => 'image/jpeg',
     298                                'filesize'  => 750,
    297299                        ),
    298300
    299301                        // #1
    class Tests_Image_Editor_GD extends WP_Image_UnitTestCase { 
    302304                                'width'     => 75,
    303305                                'height'    => 50,
    304306                                'mime-type' => 'image/jpeg',
     307                                'filesize'  => 1669,
    305308                        ),
    306309
    307310                        // #2
    class Tests_Image_Editor_GD extends WP_Image_UnitTestCase { 
    310313                                'width'     => 30,
    311314                                'height'    => 20,
    312315                                'mime-type' => 'image/jpeg',
     316                                'filesize'  => 958,
    313317                        ),
    314318
    315319                        // #3
    class Tests_Image_Editor_GD extends WP_Image_UnitTestCase { 
    318322                                'width'     => 45,
    319323                                'height'    => 400,
    320324                                'mime-type' => 'image/jpeg',
     325                                'filesize'  => 4100,
    321326                        ),
    322327
    323328                        // #4
    class Tests_Image_Editor_GD extends WP_Image_UnitTestCase { 
    326331                                'width'     => 50,
    327332                                'height'    => 33,
    328333                                'mime-type' => 'image/jpeg',
     334                                'filesize'  => 1244,
    329335                        ),
    330336
    331337                        // #5
    class Tests_Image_Editor_GD extends WP_Image_UnitTestCase { 
    334340                                'width'     => 55,
    335341                                'height'    => 37,
    336342                                'mime-type' => 'image/jpeg',
     343                                'filesize'  => 1344,
    337344                        ),
    338345
    339346                        // #6
    class Tests_Image_Editor_GD extends WP_Image_UnitTestCase { 
    342349                                'width'     => 83,
    343350                                'height'    => 55,
    344351                                'mime-type' => 'image/jpeg',
     352                                'filesize'  => 1891,
    345353                        ),
    346354
    347355                        // #7
    class Tests_Image_Editor_GD extends WP_Image_UnitTestCase { 
    350358                                'width'     => 90,
    351359                                'height'    => 60,
    352360                                'mime-type' => 'image/jpeg',
     361                                'filesize'  => 2059,
    353362                        ),
    354363
    355364                        // #8
    class Tests_Image_Editor_GD extends WP_Image_UnitTestCase { 
    358367                                'width'     => 105,
    359368                                'height'    => 70,
    360369                                'mime-type' => 'image/jpeg',
     370                                'filesize'  => 2405,
    361371                        ),
    362372
    363373                        // #9
    class Tests_Image_Editor_GD extends WP_Image_UnitTestCase { 
    366376                                'width'     => 200,
    367377                                'height'    => 133,
    368378                                'mime-type' => 'image/jpeg',
     379                                'filesize'  => 5569,
    369380                        ),
    370381                );
    371382
  • tests/phpunit/tests/image/editorImagick.php

    diff --git a/tests/phpunit/tests/image/editorImagick.php b/tests/phpunit/tests/image/editorImagick.php
    index 812b112b77..26b851c4c4 100644
    a b class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase { 
    8888                                'width'     => 50,
    8989                                'height'    => 33,
    9090                                'mime-type' => 'image/jpeg',
     91                                'filesize'  => 6876,
    9192                        ),
    9293                );
    9394
    class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase { 
    287288                                'width'     => 10,
    288289                                'height'    => 7,
    289290                                'mime-type' => 'image/jpeg',
     291                                'filesize'  => 6235,
    290292                        ),
    291293
    292294                        // #1
    class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase { 
    295297                                'width'     => 75,
    296298                                'height'    => 50,
    297299                                'mime-type' => 'image/jpeg',
     300                                'filesize'  => 7462,
    298301                        ),
    299302
    300303                        // #2
    class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase { 
    303306                                'width'     => 30,
    304307                                'height'    => 20,
    305308                                'mime-type' => 'image/jpeg',
     309                                'filesize'  => 6508,
    306310                        ),
    307311
    308312                        // #3
    class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase { 
    311315                                'width'     => 45,
    312316                                'height'    => 400,
    313317                                'mime-type' => 'image/jpeg',
     318                                'filesize'  => 10316,
    314319                        ),
    315320
    316321                        // #4
    class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase { 
    319324                                'width'     => 50,
    320325                                'height'    => 33,
    321326                                'mime-type' => 'image/jpeg',
     327                                'filesize'  => 6876,
    322328                        ),
    323329
    324330                        // #5
    class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase { 
    327333                                'width'     => 55,
    328334                                'height'    => 37,
    329335                                'mime-type' => 'image/jpeg',
     336                                'filesize'  => 6997,
    330337                        ),
    331338
    332339                        // #6
    class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase { 
    335342                                'width'     => 83,
    336343                                'height'    => 55,
    337344                                'mime-type' => 'image/jpeg',
     345                                'filesize'  => 7678,
    338346                        ),
    339347
    340348                        // #7
    class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase { 
    343351                                'width'     => 90,
    344352                                'height'    => 60,
    345353                                'mime-type' => 'image/jpeg',
     354                                'filesize'  => 7916,
    346355                        ),
    347356
    348357                        // #8
    class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase { 
    351360                                'width'     => 105,
    352361                                'height'    => 70,
    353362                                'mime-type' => 'image/jpeg',
     363                                'filesize'  => 8338,
    354364                        ),
    355365
    356366                        // #9
    class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase { 
    359369                                'width'     => 200,
    360370                                'height'    => 133,
    361371                                'mime-type' => 'image/jpeg',
     372                                'filesize'  => 12347,
    362373                        ),
    363374                );
    364375
  • tests/phpunit/tests/image/functions.php

    diff --git a/tests/phpunit/tests/image/functions.php b/tests/phpunit/tests/image/functions.php
    index 444d730fdc..878626a144 100644
    a b class Tests_Image_Functions extends WP_UnitTestCase { 
    437437                        'sizes' => array(
    438438                                'full'      => array(
    439439                                        'file'      => 'wordpress-gsoc-flyer-pdf.jpg',
     440                                        'filesize'  => 115203,
    440441                                        'width'     => 1088,
    441442                                        'height'    => 1408,
    442443                                        'mime-type' => 'image/jpeg',
    443444                                ),
    444445                                'medium'    => array(
    445446                                        'file'      => 'wordpress-gsoc-flyer-pdf-232x300.jpg',
     447                                        'filesize'  => 13390,
    446448                                        'width'     => 232,
    447449                                        'height'    => 300,
    448450                                        'mime-type' => 'image/jpeg',
    449451                                ),
    450452                                'large'     => array(
    451453                                        'file'      => 'wordpress-gsoc-flyer-pdf-791x1024.jpg',
     454                                        'filesize'  => 66248,
    452455                                        'width'     => 791,
    453456                                        'height'    => 1024,
    454457                                        'mime-type' => 'image/jpeg',
    455458                                ),
    456459                                'thumbnail' => array(
    457460                                        'file'      => 'wordpress-gsoc-flyer-pdf-116x150.jpg',
     461                                        'filesize'  => 5945,
    458462                                        'width'     => 116,
    459463                                        'height'    => 150,
    460464                                        'mime-type' => 'image/jpeg',
    461465                                ),
    462466                        ),
     467                        'filesize' => 12895,
    463468                );
    464469
    465470                $metadata = wp_generate_attachment_metadata( $attachment_id, $test_file );
    class Tests_Image_Functions extends WP_UnitTestCase { 
    502507                        'sizes' => array(
    503508                                'full'      => array(
    504509                                        'file'      => 'wordpress-gsoc-flyer-pdf.jpg',
     510                                        'filesize'  => 115203,
    505511                                        'width'     => 1088,
    506512                                        'height'    => 1408,
    507513                                        'mime-type' => 'image/jpeg',
    508514                                ),
    509515                                'medium'    => array(
    510516                                        'file'      => 'wordpress-gsoc-flyer-pdf-300x300.jpg',
     517                                        'filesize'  => 17897,
    511518                                        'width'     => 300,
    512519                                        'height'    => 300,
    513520                                        'mime-type' => 'image/jpeg',
    514521                                ),
    515522                                'large'     => array(
    516523                                        'file'      => 'wordpress-gsoc-flyer-pdf-791x1024.jpg',
     524                                        'filesize'  => 66248,
    517525                                        'width'     => 791,
    518526                                        'height'    => 1024,
    519527                                        'mime-type' => 'image/jpeg',
    520528                                ),
    521529                                'thumbnail' => array(
    522530                                        'file'      => 'wordpress-gsoc-flyer-pdf-116x150.jpg',
     531                                        'filesize'  => 5945,
    523532                                        'width'     => 116,
    524533                                        'height'    => 150,
    525534                                        'mime-type' => 'image/jpeg',
    526535                                ),
    527536                        ),
     537                        'filesize' => 12895,
    528538                );
    529539
    530540                $metadata = wp_generate_attachment_metadata( $attachment_id, $test_file );
    class Tests_Image_Functions extends WP_UnitTestCase { 
    563573
    564574                $expected = array(
    565575                        'file'      => 'wordpress-gsoc-flyer-pdf-77x100.jpg',
     576                        'filesize'  => 4575,
    566577                        'width'     => 77,
    567578                        'height'    => 100,
    568579                        'mime-type' => 'image/jpeg',
  • new file tests/phpunit/tests/media/filesize.php

    diff --git a/tests/phpunit/tests/media/filesize.php b/tests/phpunit/tests/media/filesize.php
    new file mode 100644
    index 0000000000..26a5228dc5
    - +  
     1<?php
     2
     3/**
     4 * @group media
     5 * @group media_filesize
     6 */
     7class Tests_Image_Filesize extends WP_UnitTestCase {
     8        function tearDown() {
     9                $this->remove_added_uploads();
     10
     11                parent::tearDown();
     12        }
     13
     14        /**
     15         * Check that filesize meta is generated for jpegs.
     16         *
     17         * @ticket 49412
     18         */
     19        function test_filesize_in_jpg_meta() {
     20                $attachment = $this->factory->attachment->create_upload_object( DIR_TESTDATA . '/images/33772.jpg' );
     21
     22                $metadata = wp_get_attachment_metadata( $attachment );
     23
     24                $this->assertEquals( $metadata['filesize'], 176615 );
     25
     26                foreach ( $metadata['sizes'] as $intermediate_size ) {
     27                        $this->assertTrue( ! empty( $intermediate_size['filesize'] ) && is_numeric( $intermediate_size['filesize'] ) );
     28                }
     29        }
     30
     31        /**
     32         * Check that filesize meta is generated for pngs.
     33         *
     34         * @ticket 49412
     35         */
     36        function test_filesize_in_png_meta() {
     37                $attachment = $this->factory->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image-large.png' );
     38
     39                $metadata = wp_get_attachment_metadata( $attachment );
     40
     41                $this->assertEquals( $metadata['filesize'], 4409 );
     42
     43                foreach ( $metadata['sizes'] as $intermediate_size ) {
     44                        $this->assertTrue( ! empty( $intermediate_size['filesize'] ) && is_numeric( $intermediate_size['filesize'] ) );
     45                }
     46        }
     47
     48        /**
     49         * Check that filesize meta is generated for pdfs.
     50         *
     51         * @ticket 49412
     52         */
     53        function test_filesize_in_pdf_meta() {
     54                $attachment = $this->factory->attachment->create_upload_object( DIR_TESTDATA . '/images/wordpress-gsoc-flyer.pdf' );
     55
     56                $metadata = wp_get_attachment_metadata( $attachment );
     57
     58                $this->assertEquals( $metadata['filesize'], 12895 );
     59
     60                foreach ( $metadata['sizes'] as $intermediate_size ) {
     61                        $this->assertTrue( ! empty( $intermediate_size['filesize'] ) && is_numeric( $intermediate_size['filesize'] ) );
     62                }
     63        }
     64
     65        /**
     66         * Check that filesize meta is generated for psds.
     67         *
     68         * @ticket 49412
     69         */
     70        function test_filesize_in_psd_meta() {
     71                $attachment = $this->factory->attachment->create_upload_object( DIR_TESTDATA . '/images/test-image.psd' );
     72
     73                $metadata = wp_get_attachment_metadata( $attachment );
     74
     75                $this->assertEquals( $metadata['filesize'], 41154 );
     76        }
     77}