Ticket #49412: 49412.diff
File 49412.diff, 12.2 KB (added by , 5 years ago) |
---|
-
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 ) { 233 233 234 234 // Default image meta. 235 235 $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(), 240 241 ); 241 242 242 243 // Fetch additional metadata from EXIF/IPTC. … … function wp_generate_attachment_metadata( $attachment_id, $file ) { 611 612 unset( $metadata['image']['data'] ); 612 613 } 613 614 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 614 620 /** 615 621 * Filters the generated attachment meta data. 616 622 * -
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 { 463 463 return array( 464 464 'path' => $filename, 465 465 'file' => wp_basename( apply_filters( 'image_make_intermediate_size', $filename ) ), 466 'filesize' => filesize( $filename ), 466 467 'width' => $this->size['width'], 467 468 'height' => $this->size['height'], 468 469 '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 { 696 696 'path' => $filename, 697 697 /** This filter is documented in wp-includes/class-wp-image-editor-gd.php */ 698 698 'file' => wp_basename( apply_filters( 'image_make_intermediate_size', $filename ) ), 699 'filesize' => filesize( $filename ), 699 700 'width' => $this->size['width'], 700 701 'height' => $this->size['height'], 701 702 '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 { 95 95 'width' => 50, 96 96 'height' => 33, 97 97 'mime-type' => 'image/jpeg', 98 'filesize' => 1244, 98 99 ), 99 100 ); 100 101 … … class Tests_Image_Editor_GD extends WP_Image_UnitTestCase { 294 295 'width' => 10, 295 296 'height' => 7, 296 297 'mime-type' => 'image/jpeg', 298 'filesize' => 750, 297 299 ), 298 300 299 301 // #1 … … class Tests_Image_Editor_GD extends WP_Image_UnitTestCase { 302 304 'width' => 75, 303 305 'height' => 50, 304 306 'mime-type' => 'image/jpeg', 307 'filesize' => 1669, 305 308 ), 306 309 307 310 // #2 … … class Tests_Image_Editor_GD extends WP_Image_UnitTestCase { 310 313 'width' => 30, 311 314 'height' => 20, 312 315 'mime-type' => 'image/jpeg', 316 'filesize' => 958, 313 317 ), 314 318 315 319 // #3 … … class Tests_Image_Editor_GD extends WP_Image_UnitTestCase { 318 322 'width' => 45, 319 323 'height' => 400, 320 324 'mime-type' => 'image/jpeg', 325 'filesize' => 4100, 321 326 ), 322 327 323 328 // #4 … … class Tests_Image_Editor_GD extends WP_Image_UnitTestCase { 326 331 'width' => 50, 327 332 'height' => 33, 328 333 'mime-type' => 'image/jpeg', 334 'filesize' => 1244, 329 335 ), 330 336 331 337 // #5 … … class Tests_Image_Editor_GD extends WP_Image_UnitTestCase { 334 340 'width' => 55, 335 341 'height' => 37, 336 342 'mime-type' => 'image/jpeg', 343 'filesize' => 1344, 337 344 ), 338 345 339 346 // #6 … … class Tests_Image_Editor_GD extends WP_Image_UnitTestCase { 342 349 'width' => 83, 343 350 'height' => 55, 344 351 'mime-type' => 'image/jpeg', 352 'filesize' => 1891, 345 353 ), 346 354 347 355 // #7 … … class Tests_Image_Editor_GD extends WP_Image_UnitTestCase { 350 358 'width' => 90, 351 359 'height' => 60, 352 360 'mime-type' => 'image/jpeg', 361 'filesize' => 2059, 353 362 ), 354 363 355 364 // #8 … … class Tests_Image_Editor_GD extends WP_Image_UnitTestCase { 358 367 'width' => 105, 359 368 'height' => 70, 360 369 'mime-type' => 'image/jpeg', 370 'filesize' => 2405, 361 371 ), 362 372 363 373 // #9 … … class Tests_Image_Editor_GD extends WP_Image_UnitTestCase { 366 376 'width' => 200, 367 377 'height' => 133, 368 378 'mime-type' => 'image/jpeg', 379 'filesize' => 5569, 369 380 ), 370 381 ); 371 382 -
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 { 88 88 'width' => 50, 89 89 'height' => 33, 90 90 'mime-type' => 'image/jpeg', 91 'filesize' => 6876, 91 92 ), 92 93 ); 93 94 … … class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase { 287 288 'width' => 10, 288 289 'height' => 7, 289 290 'mime-type' => 'image/jpeg', 291 'filesize' => 6235, 290 292 ), 291 293 292 294 // #1 … … class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase { 295 297 'width' => 75, 296 298 'height' => 50, 297 299 'mime-type' => 'image/jpeg', 300 'filesize' => 7462, 298 301 ), 299 302 300 303 // #2 … … class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase { 303 306 'width' => 30, 304 307 'height' => 20, 305 308 'mime-type' => 'image/jpeg', 309 'filesize' => 6508, 306 310 ), 307 311 308 312 // #3 … … class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase { 311 315 'width' => 45, 312 316 'height' => 400, 313 317 'mime-type' => 'image/jpeg', 318 'filesize' => 10316, 314 319 ), 315 320 316 321 // #4 … … class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase { 319 324 'width' => 50, 320 325 'height' => 33, 321 326 'mime-type' => 'image/jpeg', 327 'filesize' => 6876, 322 328 ), 323 329 324 330 // #5 … … class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase { 327 333 'width' => 55, 328 334 'height' => 37, 329 335 'mime-type' => 'image/jpeg', 336 'filesize' => 6997, 330 337 ), 331 338 332 339 // #6 … … class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase { 335 342 'width' => 83, 336 343 'height' => 55, 337 344 'mime-type' => 'image/jpeg', 345 'filesize' => 7678, 338 346 ), 339 347 340 348 // #7 … … class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase { 343 351 'width' => 90, 344 352 'height' => 60, 345 353 'mime-type' => 'image/jpeg', 354 'filesize' => 7916, 346 355 ), 347 356 348 357 // #8 … … class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase { 351 360 'width' => 105, 352 361 'height' => 70, 353 362 'mime-type' => 'image/jpeg', 363 'filesize' => 8338, 354 364 ), 355 365 356 366 // #9 … … class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase { 359 369 'width' => 200, 360 370 'height' => 133, 361 371 'mime-type' => 'image/jpeg', 372 'filesize' => 12347, 362 373 ), 363 374 ); 364 375 -
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 { 437 437 'sizes' => array( 438 438 'full' => array( 439 439 'file' => 'wordpress-gsoc-flyer-pdf.jpg', 440 'filesize' => 115203, 440 441 'width' => 1088, 441 442 'height' => 1408, 442 443 'mime-type' => 'image/jpeg', 443 444 ), 444 445 'medium' => array( 445 446 'file' => 'wordpress-gsoc-flyer-pdf-232x300.jpg', 447 'filesize' => 13390, 446 448 'width' => 232, 447 449 'height' => 300, 448 450 'mime-type' => 'image/jpeg', 449 451 ), 450 452 'large' => array( 451 453 'file' => 'wordpress-gsoc-flyer-pdf-791x1024.jpg', 454 'filesize' => 66248, 452 455 'width' => 791, 453 456 'height' => 1024, 454 457 'mime-type' => 'image/jpeg', 455 458 ), 456 459 'thumbnail' => array( 457 460 'file' => 'wordpress-gsoc-flyer-pdf-116x150.jpg', 461 'filesize' => 5945, 458 462 'width' => 116, 459 463 'height' => 150, 460 464 'mime-type' => 'image/jpeg', 461 465 ), 462 466 ), 467 'filesize' => 12895, 463 468 ); 464 469 465 470 $metadata = wp_generate_attachment_metadata( $attachment_id, $test_file ); … … class Tests_Image_Functions extends WP_UnitTestCase { 502 507 'sizes' => array( 503 508 'full' => array( 504 509 'file' => 'wordpress-gsoc-flyer-pdf.jpg', 510 'filesize' => 115203, 505 511 'width' => 1088, 506 512 'height' => 1408, 507 513 'mime-type' => 'image/jpeg', 508 514 ), 509 515 'medium' => array( 510 516 'file' => 'wordpress-gsoc-flyer-pdf-300x300.jpg', 517 'filesize' => 17897, 511 518 'width' => 300, 512 519 'height' => 300, 513 520 'mime-type' => 'image/jpeg', 514 521 ), 515 522 'large' => array( 516 523 'file' => 'wordpress-gsoc-flyer-pdf-791x1024.jpg', 524 'filesize' => 66248, 517 525 'width' => 791, 518 526 'height' => 1024, 519 527 'mime-type' => 'image/jpeg', 520 528 ), 521 529 'thumbnail' => array( 522 530 'file' => 'wordpress-gsoc-flyer-pdf-116x150.jpg', 531 'filesize' => 5945, 523 532 'width' => 116, 524 533 'height' => 150, 525 534 'mime-type' => 'image/jpeg', 526 535 ), 527 536 ), 537 'filesize' => 12895, 528 538 ); 529 539 530 540 $metadata = wp_generate_attachment_metadata( $attachment_id, $test_file ); … … class Tests_Image_Functions extends WP_UnitTestCase { 563 573 564 574 $expected = array( 565 575 'file' => 'wordpress-gsoc-flyer-pdf-77x100.jpg', 576 'filesize' => 4575, 566 577 'width' => 77, 567 578 'height' => 100, 568 579 '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..3ccf574d0b
- + 1 <?php 2 3 /** 4 * @group media 5 * @group media_filesize 6 */ 7 class 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 print_r( $metadata ); 76 77 $this->assertEquals( $metadata['filesize'], 41154 ); 78 } 79 }