public function multi_resize($sizes) { $is_animated_gif = GifFrameExtractor::isAnimatedGif($this->file); if (!$is_animated_gif) { return parent::multi_resize($sizes); } $metadata = array(); $orig_size = $this->size; foreach ($sizes as $size => $size_data) { $image = $this->_resize_animated_gif($size_data['width'], $size_data['height'], $size_data['crop']); if (!is_wp_error($image)) { $resized = $this->_save_animated_gif($image); unset($image); if (!is_wp_error($resized) && $resized) { unset($resized['path']); $metadata[$size] = $resized; } } $this->size = $orig_size; } return $metadata; }
/** * Test multi_resize with multiple sizes * * ticket 26823 */ public function test_multi_resize() { $file = DIR_TESTDATA . '/images/waffles.jpg'; $gd_image_editor = new WP_Image_Editor_GD($file); $gd_image_editor->load(); $sizes_array = array(array('width' => 10, 'height' => 10, 'crop' => false), array('width' => 75, 'height' => 50, 'crop' => true), array('width' => 9999, 'height' => 20, 'crop' => false), array('width' => 45, 'height' => 9999, 'crop' => true), array('width' => 50), array('width' => 55, 'height' => null), array('height' => 55), array('width' => null, 'height' => 60), array('width' => -9999, 'height' => 70), array('width' => 200, 'height' => -9999)); $resized = $gd_image_editor->multi_resize($sizes_array); $expected_array = array(array('file' => 'waffles-10x7.jpg', 'width' => 10, 'height' => 7, 'mime-type' => 'image/jpeg'), array('file' => 'waffles-75x50.jpg', 'width' => 75, 'height' => 50, 'mime-type' => 'image/jpeg'), array('file' => 'waffles-30x20.jpg', 'width' => 30, 'height' => 20, 'mime-type' => 'image/jpeg'), array('file' => 'waffles-45x400.jpg', 'width' => 45, 'height' => 400, 'mime-type' => 'image/jpeg'), array('file' => 'waffles-50x33.jpg', 'width' => 50, 'height' => 33, 'mime-type' => 'image/jpeg'), array('file' => 'waffles-55x37.jpg', 'width' => 55, 'height' => 37, 'mime-type' => 'image/jpeg'), array('file' => 'waffles-83x55.jpg', 'width' => 83, 'height' => 55, 'mime-type' => 'image/jpeg'), array('file' => 'waffles-90x60.jpg', 'width' => 90, 'height' => 60, 'mime-type' => 'image/jpeg'), array('file' => 'waffles-105x70.jpg', 'width' => 105, 'height' => 70, 'mime-type' => 'image/jpeg'), array('file' => 'waffles-200x133.jpg', 'width' => 200, 'height' => 133, 'mime-type' => 'image/jpeg')); $this->assertNotNull($resized); $this->assertEquals($expected_array, $resized); foreach ($resized as $key => $image_data) { $image_path = DIR_TESTDATA . '/images/' . $image_data['file']; // Now, verify real dimensions are as expected $this->assertImageDimensions($image_path, $expected_array[$key]['width'], $expected_array[$key]['height']); } }
/** * Test multi_resize with multiple sizes * * ticket 26823 */ public function test_multi_resize() { $file = DIR_TESTDATA . '/images/waffles.jpg'; $gd_image_editor = new WP_Image_Editor_GD( $file ); $gd_image_editor->load(); $sizes_array = array( /** * #0 - 10x10 resize, no cropping. * By aspect, should be 10x6 output. */ array( 'width' => 10, 'height' => 10, 'crop' => false, ), /** * #1 - 75x50 resize, with cropping. * Output dimensions should be 75x50 */ array( 'width' => 75, 'height' => 50, 'crop' => true, ), /** * #2 - 20 pixel max height, no cropping. * By aspect, should be 30x20 output. */ array( 'width' => 9999, # Arbitrary High Value 'height' => 20, 'crop' => false, ), /** * #3 - 45 pixel max height, with cropping. * By aspect, should be 45x400 output. */ array( 'width' => 45, 'height' => 9999, # Arbitrary High Value 'crop' => true, ), /** * #4 - 50 pixel max width, no cropping. * By aspect, should be 50x33 output. */ array( 'width' => 50, ), /** * #5 - 55 pixel max width, no cropping, null height * By aspect, should be 55x36 output. */ array( 'width' => 55, 'height' => null, ), /** * #6 - 55 pixel max height, no cropping, no width specified. * By aspect, should be 82x55 output. */ array( 'height' => 55, ), /** * #7 - 60 pixel max height, no cropping, null width. * By aspect, should be 90x60 output. */ array( 'width' => null, 'height' => 60, ), /** * #8 - 70 pixel max height, no cropping, negative width. * By aspect, should be 105x70 output. */ array( 'width' => -9999, # Arbitrary Negative Value 'height' => 70, ), /** * #9 - 200 pixel max width, no cropping, negative height. * By aspect, should be 200x133 output. */ array( 'width' => 200, 'height' => -9999, # Arbitrary Negative Value ), ); $resized = $gd_image_editor->multi_resize( $sizes_array ); $expected_array = array( // #0 array( 'file' => 'waffles-10x6.jpg', 'width' => 10, 'height' => 6, 'mime-type' => 'image/jpeg', ), // #1 array( 'file' => 'waffles-75x50.jpg', 'width' => 75, 'height' => 50, 'mime-type' => 'image/jpeg', ), // #2 array( 'file' => 'waffles-30x20.jpg', 'width' => 30, 'height' => 20, 'mime-type' => 'image/jpeg', ), // #3 array( 'file' => 'waffles-45x400.jpg', 'width' => 45, 'height' => 400, 'mime-type' => 'image/jpeg', ), // #4 array( 'file' => 'waffles-50x33.jpg', 'width' => 50, 'height' => 33, 'mime-type' => 'image/jpeg', ), // #5 array( 'file' => 'waffles-55x36.jpg', 'width' => 55, 'height' => 36, 'mime-type' => 'image/jpeg', ), // #6 array( 'file' => 'waffles-82x55.jpg', 'width' => 82, 'height' => 55, 'mime-type' => 'image/jpeg', ), // #7 array( 'file' => 'waffles-90x60.jpg', 'width' => 90, 'height' => 60, 'mime-type' => 'image/jpeg', ), // #8 array( 'file' => 'waffles-105x70.jpg', 'width' => 105, 'height' => 70, 'mime-type' => 'image/jpeg', ), // #9 array( 'file' => 'waffles-200x133.jpg', 'width' => 200, 'height' => 133, 'mime-type' => 'image/jpeg', ), ); $this->assertNotNull( $resized ); $this->assertEquals( $expected_array, $resized ); foreach( $resized as $key => $image_data ){ $image_path = DIR_TESTDATA . '/images/' . $image_data['file']; // Now, verify real dimensions are as expected $this->assertImageDimensions( $image_path, $expected_array[$key]['width'], $expected_array[$key]['height'] ); } }