| | 48 | * Test resizing an multi resizong image, not using crop |
| | 49 | * |
| | 50 | */ |
| | 51 | public function test_multi_resize() { |
| | 52 | |
| | 53 | $file = DIR_TESTDATA . '/images/waffles.jpg'; |
| | 54 | |
| | 55 | $gd_image_editor = new WP_Image_Editor_GD( $file ); |
| | 56 | $gd_image_editor->load(); |
| | 57 | $sizes_array = array( |
| | 58 | array ('width' => 50, 'height' => 50 ) |
| | 59 | ); |
| | 60 | $resized = $gd_image_editor->multi_resize( $sizes_array ); |
| | 61 | |
| | 62 | $expected_array = array( |
| | 63 | array ( 'file' => 'waffles-50x33.jpg', |
| | 64 | 'width' => 50, |
| | 65 | 'height' => 33, |
| | 66 | 'mime-type' => 'image/jpeg') |
| | 67 | ); |
| | 68 | |
| | 69 | $this->assertEquals( $expected_array, $resized ); |
| | 70 | } |
| | 71 | |
| | 72 | /** |
| | 73 | * Test resizing an multi resizong image, and then load the image to check size |
| | 74 | * |
| | 75 | */ |
| | 76 | public function test_multi_resize_check_is_resized() { |
| | 77 | |
| | 78 | $file = DIR_TESTDATA . '/images/waffles.jpg'; |
| | 79 | |
| | 80 | $gd_image_editor = new WP_Image_Editor_GD( $file ); |
| | 81 | $gd_image_editor->load(); |
| | 82 | $sizes_array = array( |
| | 83 | array ('width' => 50, 'height' => 50 ) |
| | 84 | ); |
| | 85 | $resized = $gd_image_editor->multi_resize( $sizes_array ); |
| | 86 | |
| | 87 | |
| | 88 | $gd_image_output = new WP_Image_Editor_GD( DIR_TESTDATA . '/images/'. $resized[0]['file'] ); |
| | 89 | $gd_image_output->load(); |
| | 90 | |
| | 91 | $this->assertEquals( array( 'width' => 50, 'height' => 33 ), $gd_image_output->get_size() ); |
| | 92 | } |
| | 93 | |
| | 94 | /** |
| | 95 | * Test resizing an multi resizong image array in array out |
| | 96 | * |
| | 97 | */ |
| | 98 | public function test_multi_resize_array() { |
| | 99 | |
| | 100 | $file = DIR_TESTDATA . '/images/waffles.jpg'; |
| | 101 | |
| | 102 | $gd_image_editor = new WP_Image_Editor_GD( $file ); |
| | 103 | $gd_image_editor->load(); |
| | 104 | $sizes_array = array( |
| | 105 | // #1 - resizes to 100x100 pixel, square-cropped image |
| | 106 | array ('width' => 10, 'height' => 10, 'crop' => false), |
| | 107 | // #2 - resizes to 200 pixel max width/height, non-cropped image |
| | 108 | array ('width' => 75, 'height' => 50, 'crop' => true), |
| | 109 | // #3 - resizes to 200 pixel max height, non-cropped image |
| | 110 | array ('width' => 9999, 'height' => 20, 'crop' => false), |
| | 111 | // #3 - resizes to 450 pixel max width, non-cropped image |
| | 112 | array ('width' => 45, 'height' => 9999, 'crop' => true) |
| | 113 | ); |
| | 114 | |
| | 115 | $resized = $gd_image_editor->multi_resize( $sizes_array ); |
| | 116 | |
| | 117 | $expected_array = array( |
| | 118 | // #1 - resizes to 100x100 pixel, square-cropped image |
| | 119 | array ( 'file' => 'waffles-10x6.jpg', |
| | 120 | 'width' => 10, |
| | 121 | 'height' => 6 , |
| | 122 | 'mime-type' => 'image/jpeg'), |
| | 123 | // #2 - resizes to 200 pixel max width/height, square-cropped image |
| | 124 | array ( 'file' => 'waffles-75x50.jpg', |
| | 125 | 'width' => 75, |
| | 126 | 'height' => 50, |
| | 127 | 'mime-type' => 'image/jpeg'), |
| | 128 | // #3 - resizes to 200 pixel max height, non-cropped image |
| | 129 | array ( 'file' => 'waffles-30x20.jpg', |
| | 130 | 'width' => 30, |
| | 131 | 'height' => 20, |
| | 132 | 'mime-type' => 'image/jpeg'), |
| | 133 | // #3 - resizes to 450 pixel max width, non-cropped image |
| | 134 | array ( 'file' => 'waffles-45x400.jpg', |
| | 135 | 'width' => 45, |
| | 136 | 'height' => 400, |
| | 137 | 'mime-type' => 'image/jpeg') |
| | 138 | ); |
| | 139 | |
| | 140 | |
| | 141 | $this->assertEquals( $expected_array, $resized ); |
| | 142 | } |
| | 143 | |
| | 144 | /** |
| | 145 | * Test resizing an image, no height |
| | 146 | * |
| | 147 | */ |
| | 148 | public function test_multi_resize_mising_height() { |
| | 149 | |
| | 150 | $file = DIR_TESTDATA . '/images/waffles.jpg'; |
| | 151 | |
| | 152 | $gd_image_editor = new WP_Image_Editor_GD( $file ); |
| | 153 | $gd_image_editor->load(); |
| | 154 | $sizes_array = array( |
| | 155 | array ('width' => 50) |
| | 156 | ); |
| | 157 | $resized = $gd_image_editor->multi_resize( $sizes_array ); |
| | 158 | |
| | 159 | $expected_array = array( |
| | 160 | array ( 'file' => 'waffles-50x33.jpg', |
| | 161 | 'width' => 50, |
| | 162 | 'height' => 33, |
| | 163 | 'mime-type' => 'image/jpeg') |
| | 164 | ); |
| | 165 | |
| | 166 | $this->assertEquals( $expected_array, $resized ); |
| | 167 | } |
| | 168 | // /** |
| | 169 | // * Test resizing an multi resize image, no width |
| | 170 | // * |
| | 171 | // */ |
| | 172 | public function test_multi_resize_mising_width() { |
| | 173 | |
| | 174 | $file = DIR_TESTDATA . '/images/waffles.jpg'; |
| | 175 | |
| | 176 | $gd_image_editor = new WP_Image_Editor_GD( $file ); |
| | 177 | $gd_image_editor->load(); |
| | 178 | $sizes_array = array( |
| | 179 | array ( 'height' => 50 ) |
| | 180 | ); |
| | 181 | $resized = $gd_image_editor->multi_resize( $sizes_array ); |
| | 182 | |
| | 183 | $expected_array = array( |
| | 184 | array ( 'file' => 'waffles-75x50.jpg', |
| | 185 | 'width' => 75, |
| | 186 | 'height' => 50, |
| | 187 | 'mime-type' => 'image/jpeg') |
| | 188 | ); |
| | 189 | |
| | 190 | $this->assertEquals( $expected_array, $resized ); |
| | 191 | } |
| | 192 | |
| | 193 | // /** |
| | 194 | // * Test resizing an multi resize image, null input |
| | 195 | // * |
| | 196 | // */ |
| | 197 | public function test_multi_resize_width_set_to_null() { |
| | 198 | |
| | 199 | $file = DIR_TESTDATA . '/images/waffles.jpg'; |
| | 200 | |
| | 201 | $gd_image_editor = new WP_Image_Editor_GD( $file ); |
| | 202 | $gd_image_editor->load(); |
| | 203 | $sizes_array = array( |
| | 204 | array ( 'height' => 50,'width' => null ) |
| | 205 | ); |
| | 206 | $resized = $gd_image_editor->multi_resize( $sizes_array ); |
| | 207 | |
| | 208 | $expected_array = array( |
| | 209 | array ( 'file' => 'waffles-75x50.jpg', |
| | 210 | 'width' => 75, |
| | 211 | 'height' => 50, |
| | 212 | 'mime-type' => 'image/jpeg') |
| | 213 | ); |
| | 214 | |
| | 215 | $this->assertEquals( $expected_array, $resized ); |
| | 216 | } |
| | 217 | // /** |
| | 218 | // * Test resizing an multi resize image, Null import |
| | 219 | // * |
| | 220 | // */ |
| | 221 | public function test_multi_resize_height_set_to_null() { |
| | 222 | |
| | 223 | $file = DIR_TESTDATA . '/images/waffles.jpg'; |
| | 224 | |
| | 225 | $gd_image_editor = new WP_Image_Editor_GD( $file ); |
| | 226 | $gd_image_editor->load(); |
| | 227 | $sizes_array = array( |
| | 228 | array ( 'height' => null,'width' => 50 ) |
| | 229 | ); |
| | 230 | $resized = $gd_image_editor->multi_resize( $sizes_array ); |
| | 231 | |
| | 232 | $expected_array = array( |
| | 233 | array ( 'file' => 'waffles-50x33.jpg', |
| | 234 | 'width' => 50, |
| | 235 | 'height' => 33, |
| | 236 | 'mime-type' => 'image/jpeg') |
| | 237 | ); |
| | 238 | |
| | 239 | $this->assertEquals( $expected_array, $resized ); |
| | 240 | } |
| | 241 | |
| | 242 | // /** |
| | 243 | // * Test resizing an multi resize image, missus value |
| | 244 | // * |
| | 245 | // */ |
| | 246 | public function test_multi_resize_width_set_to_missus() { |
| | 247 | |
| | 248 | $file = DIR_TESTDATA . '/images/waffles.jpg'; |
| | 249 | |
| | 250 | $gd_image_editor = new WP_Image_Editor_GD( $file ); |
| | 251 | $gd_image_editor->load(); |
| | 252 | $sizes_array = array( |
| | 253 | array ( 'height' => 50,'width' => -50 ) |
| | 254 | ); |
| | 255 | $resized = $gd_image_editor->multi_resize( $sizes_array ); |
| | 256 | |
| | 257 | $expected_array = array( |
| | 258 | array ( 'file' => 'waffles-75x50.jpg', |
| | 259 | 'width' => 75, |
| | 260 | 'height' => 50, |
| | 261 | 'mime-type' => 'image/jpeg') |
| | 262 | ); |
| | 263 | |
| | 264 | $this->assertEquals( $expected_array, $resized ); |
| | 265 | } |
| | 266 | // /** |
| | 267 | // * Test resizing an multi resize image, missus value |
| | 268 | // * |
| | 269 | // */ |
| | 270 | public function test_multi_resize_height_set_to_missus() { |
| | 271 | |
| | 272 | $file = DIR_TESTDATA . '/images/waffles.jpg'; |
| | 273 | |
| | 274 | $gd_image_editor = new WP_Image_Editor_GD( $file ); |
| | 275 | $gd_image_editor->load(); |
| | 276 | $sizes_array = array( |
| | 277 | array ( 'height' => -65119,'width' => 200 ) |
| | 278 | ); |
| | 279 | $resized = $gd_image_editor->multi_resize( $sizes_array ); |
| | 280 | |
| | 281 | $expected_array = array( |
| | 282 | array ( 'file' => 'waffles-200x133.jpg', |
| | 283 | 'width' => 200, |
| | 284 | 'height' => 133, |
| | 285 | 'mime-type' => 'image/jpeg') |
| | 286 | ); |
| | 287 | |
| | 288 | $this->assertEquals( $expected_array, $resized ); |
| | 289 | } |
| | 290 | |
| | 291 | |
| | 292 | |
| | 293 | /** |