| 188 | | * @param string $name The image size name. |
| 189 | | * @param int $width The image's width. |
| 190 | | * @param int $height The image's width. |
| 191 | | * @param bool $width Whether to crop the image to fit the dimensions. Default false. |
| | 188 | * Cropping behavior is dependent on the value of $crop: |
| | 189 | * 1. If false (default), images will not be cropped. |
| | 190 | * 2. If true, images will be cropped to the specified dimensions. |
| | 191 | * 3. If an array, must contain the x_crop_position and y_crop_position |
| | 192 | * keys and their respective values: |
| | 193 | * - x_crop_position accepts 'left' 'center', or 'right'. |
| | 194 | * - y_crop_position accepts 'top', 'center', or 'bottom'. |
| | 195 | * Images will be cropped to the specified dimensions within the defined |
| | 196 | * crop area. |
| | 197 | * |
| | 198 | * @param string $name Image size identifier. |
| | 199 | * @param int $width Image width in pixels. |
| | 200 | * @param int $height Image height in pixels. |
| | 201 | * @param bool|array $crop Optional, default is false. Whether to crop image |
| | 202 | * to specified height and width or resize. An array |
| | 203 | * can specify positioning of the crop area. |
| | 204 | * @return bool|array False, if no image was created. Metadata array on success. |
| | 364 | * Cropping behavior is dependent on the value of $crop: |
| | 365 | * 1. If false (default), images will not be cropped. |
| | 366 | * 2. If true, images will be cropped to the specified dimensions. |
| | 367 | * 3. If an array, must contain the x_crop_position and y_crop_position |
| | 368 | * keys and their respective values: |
| | 369 | * - x_crop_position accepts 'left' 'center', or 'right'. |
| | 370 | * - y_crop_position accepts 'top', 'center', or 'bottom'. |
| | 371 | * Images will be cropped to the specified dimensions within the defined |
| | 372 | * crop area. |
| | 373 | * |
| 355 | | * @param int $orig_w Original width. |
| 356 | | * @param int $orig_h Original height. |
| 357 | | * @param int $dest_w New width. |
| 358 | | * @param int $dest_h New height. |
| 359 | | * @param bool $crop Optional, default is false. Whether to crop image or resize. |
| 360 | | * @return bool|array False on failure. Returned array matches parameters for imagecopyresampled() PHP function. |
| | 376 | * @uses apply_filters() Calls 'image_resize_dimensions' on $orig_w, $orig_h, |
| | 377 | * $dest_w, $dest_h and $crop to provide custom resize |
| | 378 | * dimensions. |
| | 379 | * |
| | 380 | * @param int $orig_w Original width in pixels. |
| | 381 | * @param int $orig_h Original height in pixels. |
| | 382 | * @param int $dest_w New width in pixels. |
| | 383 | * @param int $dest_h New height in pixels. |
| | 384 | * @param bool|array $crop Optional. Whether to crop image to specified height and width or resize. |
| | 385 | * An array can specify positioning of the crop area. Default false. |
| | 386 | * @return bool|array False on failure. Returned array matches parameters for `imagecopyresampled()`. |
| 394 | | $s_x = floor( ($orig_w - $crop_w) / 2 ); |
| 395 | | $s_y = floor( ($orig_h - $crop_h) / 2 ); |
| | 420 | if ( ! is_array( $crop ) || count( $crop ) !== 2 ) { |
| | 421 | $crop = apply_filters( 'image_resize_crop_default', array( 'center', 'center' ) ); |
| | 422 | } |
| | 423 | |
| | 424 | @list( $x, $y ) = $crop; |
| | 425 | |
| | 426 | switch ( $x ) { |
| | 427 | case 'left': |
| | 428 | $s_x = 0; |
| | 429 | break; |
| | 430 | case 'right': |
| | 431 | $s_x = $orig_w - $crop_w; |
| | 432 | break; |
| | 433 | default: |
| | 434 | $s_x = floor( ( $orig_w - $crop_w ) / 2 ); |
| | 435 | break; |
| | 436 | } |
| | 437 | |
| | 438 | switch ( $y ) { |
| | 439 | case 'top': |
| | 440 | $s_y = 0; |
| | 441 | break; |
| | 442 | case 'bottom': |
| | 443 | $s_y = $orig_h - $crop_h; |
| | 444 | break; |
| | 445 | default: |
| | 446 | $s_y = floor( ( $orig_h - $crop_h ) / 2 ); |
| | 447 | break; |
| | 448 | } |