diff --git a/src/wp-includes/class-wp-image-editor-imagick.php b/src/wp-includes/class-wp-image-editor-imagick.php
index 4d49e55b2c..330bf65f76 100644
|
a
|
b
|
class WP_Image_Editor_Imagick extends WP_Image_Editor { |
| 71 | 71 | 'flipimage', |
| 72 | 72 | 'flopimage', |
| 73 | 73 | 'readimage', |
| | 74 | 'readimageblob', |
| 74 | 75 | ); |
| 75 | 76 | |
| 76 | 77 | // Now, test for deep requirements within Imagick. |
| … |
… |
class WP_Image_Editor_Imagick extends WP_Image_Editor { |
| 148 | 149 | |
| 149 | 150 | // Reading image after Imagick instantiation because `setResolution` |
| 150 | 151 | // only applies correctly before the image is read. |
| 151 | | $this->image->readImage( $filename ); |
| | 152 | if ( wp_is_stream( $filename ) ) { |
| | 153 | // Imagick::readImageFile doesn't properly support streams. |
| | 154 | $this->image->readImageBlob( file_get_contents( $filename ), $filename ); |
| | 155 | } else { |
| | 156 | $this->image->readImage( $filename ); |
| | 157 | } |
| 152 | 158 | |
| 153 | 159 | if ( ! $this->image->valid() ) { |
| 154 | 160 | return new WP_Error( 'invalid_image', __( 'File is not an image.' ), $this->file ); |
| … |
… |
class WP_Image_Editor_Imagick extends WP_Image_Editor { |
| 678 | 684 | $orig_format = $this->image->getImageFormat(); |
| 679 | 685 | |
| 680 | 686 | $this->image->setImageFormat( strtoupper( $this->get_extension( $mime_type ) ) ); |
| 681 | | $this->make_image( $filename, array( $image, 'writeImage' ), array( $filename ) ); |
| | 687 | |
| | 688 | if ( wp_is_stream( $filename ) ) { |
| | 689 | // Imagick::writeImageFile doesn't support streams properly, so copy the blob. |
| | 690 | file_put_contents( $filename, $image->getImageBlob() ); |
| | 691 | } else { |
| | 692 | $this->make_image( $filename, array( $image, 'writeImage' ), array( $filename ) ); |
| | 693 | } |
| 682 | 694 | |
| 683 | 695 | // Reset original format. |
| 684 | 696 | $this->image->setImageFormat( $orig_format ); |
diff --git a/src/wp-includes/class-wp-image-editor.php b/src/wp-includes/class-wp-image-editor.php
index 7b20382887..7c2312304f 100644
|
a
|
b
|
abstract class WP_Image_Editor { |
| 365 | 365 | $new_ext = strtolower( $extension ? $extension : $ext ); |
| 366 | 366 | |
| 367 | 367 | if ( ! is_null( $dest_path ) ) { |
| 368 | | $_dest_path = realpath( $dest_path ); |
| 369 | | if ( $_dest_path ) { |
| 370 | | $dir = $_dest_path; |
| | 368 | if ( ! wp_is_stream( $dest_path ) ) { |
| | 369 | $_dest_path = realpath( $dest_path ); |
| | 370 | if ( $_dest_path ) { |
| | 371 | $dir = $_dest_path; |
| | 372 | } |
| | 373 | } else { |
| | 374 | $dir = $dest_path; |
| 371 | 375 | } |
| 372 | 376 | } |
| 373 | 377 | |
diff --git a/tests/phpunit/tests/image/editor.php b/tests/phpunit/tests/image/editor.php
index f602915331..3d47460560 100644
|
a
|
b
|
class Tests_Image_Editor extends WP_Image_UnitTestCase { |
| 143 | 143 | |
| 144 | 144 | // Combo! |
| 145 | 145 | $this->assertEquals( trailingslashit( realpath( get_temp_dir() ) ) . 'canola-new.png', $editor->generate_filename( 'new', realpath( get_temp_dir() ), 'png' ) ); |
| | 146 | |
| | 147 | // Test with a stream destination. |
| | 148 | $this->assertEquals( 'file://testing/path/canola-100x50.jpg', $editor->generate_filename( null, 'file://testing/path' ) ); |
| 146 | 149 | } |
| 147 | 150 | |
| 148 | 151 | /** |
diff --git a/tests/phpunit/tests/image/editorImagick.php b/tests/phpunit/tests/image/editorImagick.php
index 812b112b77..69ae4bb240 100644
|
a
|
b
|
class Tests_Image_Editor_Imagick extends WP_Image_UnitTestCase { |
| 577 | 577 | unlink( $ret['path'] ); |
| 578 | 578 | } |
| 579 | 579 | |
| | 580 | /** |
| | 581 | * Test that images can be loaded and written over streams |
| | 582 | */ |
| | 583 | public function test_streams() { |
| | 584 | $file = 'file://' . DIR_TESTDATA . '/images/waffles.jpg'; |
| | 585 | $imagick_image_editor = new WP_Image_Editor_Imagick( $file ); |
| | 586 | $imagick_image_editor->load(); |
| | 587 | $this->assertNotWPError( $imagick_image_editor ); |
| | 588 | |
| | 589 | $temp_file = 'file://' . get_temp_dir() . 'waffles.jpg'; |
| | 590 | $ret = $imagick_image_editor->save( $temp_file ); |
| | 591 | $this->assertNotWPError( $ret ); |
| | 592 | |
| | 593 | $this->assertEquals( $temp_file , $ret['path'] ); |
| | 594 | |
| | 595 | if ( $temp_file != $ret['path'] ) { |
| | 596 | unlink( $ret['path'] ); |
| | 597 | } |
| | 598 | unlink( $temp_file ); |
| | 599 | } |
| 580 | 600 | } |