Ticket #39875: 39875.2.patch
File 39875.2.patch, 5.1 KB (added by , 8 years ago) |
---|
-
src/wp-admin/includes/image.php
251 251 $editor = wp_get_image_editor( $file ); 252 252 253 253 if ( ! is_wp_error( $editor ) ) { // No support for this type of file 254 $uploaded = $editor->save( $file, 'image/jpeg' ); 254 /* 255 * PDFs may have the same file filename as JPGs. 256 * Ensure the PDF preview image does not overwrite any JPG images that already exist. 257 */ 258 $dirname = dirname( $file ); 259 $filename = preg_replace( '/\.[^.]+$/', '', $file ) . '-pdf.pdf'; 260 $filename = $dirname . '/' . wp_unique_filename( $dirname, wp_basename( $filename ) ); 261 262 $uploaded = $editor->save( $filename, 'image/jpeg' ); 255 263 unset( $editor ); 256 264 257 265 // Resize based on the full size image, rather than the source. -
tests/phpunit/data/images/test-image.pdf
1 %PDF-1.1 2 %¥±ë 3 4 1 0 obj 5 << /Type /Catalog 6 /Pages 2 0 R 7 >> 8 endobj 9 10 2 0 obj 11 << /Type /Pages 12 /Kids [3 0 R] 13 /Count 1 14 /MediaBox [0 0 612 792] 15 >> 16 endobj 17 18 3 0 obj 19 << /Type /Page 20 /Parent 2 0 R 21 /Resources 22 << /Font 23 << /F1 24 << /Type /Font 25 /Subtype /Type1 26 /BaseFont /Times-Roman 27 >> 28 >> 29 >> 30 /Contents 4 0 R 31 >> 32 endobj 33 34 4 0 obj 35 << /Length 55 >> 36 stream 37 BT 38 /F1 18 Tf 39 0 0 Td 40 (Hello World) Tj 41 ET 42 endstream 43 endobj 44 45 xref 46 0 5 47 0000000000 65535 f 48 0000000018 00000 n 49 0000000077 00000 n 50 0000000178 00000 n 51 0000000457 00000 n 52 trailer 53 << /Root 1 0 R 54 /Size 5 55 >> 56 startxref 57 565 58 %%EOF -
tests/phpunit/tests/image/functions.php
Property changes on: tests/phpunit/data/images/test-image.pdf ___________________________________________________________________ Added: svn:executable ## -0,0 +1 ## +* \ No newline at end of property
373 373 $expected = array( 374 374 'sizes' => array( 375 375 'thumbnail' => array( 376 'file' => "wordpress-gsoc-flyer- 116x150.jpg",376 'file' => "wordpress-gsoc-flyer-pdf-116x150.jpg", 377 377 'width' => 116, 378 378 'height' => 150, 379 379 'mime-type' => "image/jpeg", 380 380 ), 381 381 'medium' => array( 382 'file' => "wordpress-gsoc-flyer- 232x300.jpg",382 'file' => "wordpress-gsoc-flyer-pdf-232x300.jpg", 383 383 'width' => 232, 384 384 'height' => 300, 385 385 'mime-type' => "image/jpeg", 386 386 ), 387 387 'large' => array( 388 'file' => "wordpress-gsoc-flyer- 791x1024.jpg",388 'file' => "wordpress-gsoc-flyer-pdf-791x1024.jpg", 389 389 'width' => 791, 390 390 'height' => 1024, 391 391 'mime-type' => "image/jpeg", 392 392 ), 393 393 'full' => array( 394 'file' => "wordpress-gsoc-flyer .jpg",394 'file' => "wordpress-gsoc-flyer-pdf.jpg", 395 395 'width' => 1088, 396 396 'height' => 1408, 397 397 'mime-type' => "image/jpeg", … … 427 427 add_filter( 'fallback_intermediate_image_sizes', array( $this, 'filter_fallback_intermediate_image_sizes' ), 10, 2 ); 428 428 429 429 $expected = array( 430 'file' => 'wordpress-gsoc-flyer- 77x100.jpg',430 'file' => 'wordpress-gsoc-flyer-pdf-77x100.jpg', 431 431 'width' => 77, 432 432 'height' => 100, 433 433 'mime-type' => 'image/jpeg', … … 443 443 unlink( $test_file ); 444 444 } 445 445 446 /** 447 * Test PDF preview JPG does not overwrite an image with the same name. 448 * 449 * @ticket 39875 450 */ 451 function test_pdf_preview_does_not_overwrite_preexisting_jpg() { 452 $orig_jpg_file = DIR_TESTDATA . '/images/waffles.jpg'; 453 $test_jpg_file = '/tmp/waffles.jpg'; 454 copy( $orig_jpg_file, $test_jpg_file ); 455 456 $jpg_attachment_id = $this->factory->attachment->create_object( $test_jpg_file, 0, array( 457 'post_mime_type' => 'image/jpeg', 458 ) ); 459 460 $this->assertNotEmpty( $jpg_attachment_id ); 461 462 $jpg_metadata = wp_generate_attachment_metadata( $jpg_attachment_id, $test_jpg_file ); 463 464 $orig_pdf_file = DIR_TESTDATA . '/images/waffles.pdf'; 465 $test_pdf_file = '/tmp/waffles.pdf'; 466 copy( $orig_pdf_file, $test_pdf_file ); 467 468 $pdf_attachment_id = $this->factory->attachment->create_object( $test_pdf_file, 0, array( 469 'post_mime_type' => 'application/pdf', 470 ) ); 471 472 $this->assertNotEmpty( $pdf_attachment_id ); 473 474 $pdf_metadata = wp_generate_attachment_metadata( $pdf_attachment_id, $test_pdf_file ); 475 476 $this->assertEquals( 'waffles-pdf.jpg', $pdf_metadata['sizes']['full']['file'] ); 477 478 unlink( $test_jpg_file ); 479 unlink( $test_pdf_file ); 480 } 481 446 482 function filter_fallback_intermediate_image_sizes( $fallback_sizes, $metadata ) { 447 483 // Add the 'test-size' to the list of fallback sizes. 448 484 $fallback_sizes[] = 'test-size';