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 | |
| 189 | * Cropping behavior for the image size is dependent on the value of $crop: |
| 190 | * 1. If false (default), images will be scaled, not cropped. |
| 191 | * 2. If an array in the form of array( x_crop_position, y_crop_position ): |
| 192 | * - x_crop_position accepts 'left' 'center', or 'right'. |
| 193 | * - y_crop_position accepts 'top', 'center', or 'bottom'. |
| 194 | * Images will be cropped to the specified dimensions within the defined crop area. |
| 195 | * 3. If true, images will be cropped to the specified dimensions using center positions. |
| 196 | * |
| 197 | * @since 2.5.0 |
| 198 | * |
| 199 | * @param string $name Image size identifier. |
| 200 | * @param int $width Image width in pixels. |
| 201 | * @param int $height Image height in pixels. |
| 202 | * @param bool|array $crop Optional. Whether to crop images to specified height and width or resize. |
| 203 | * An array can specify positioning of the crop area. Default false. |
| 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 an array in the form of array( x_crop_position, y_crop_position ): |
| 367 | * - x_crop_position accepts 'left' 'center', or 'right'. |
| 368 | * - y_crop_position accepts 'top', 'center', or 'bottom'. |
| 369 | * Images will be cropped to the specified dimensions within the defined crop area. |
| 370 | * 3. If true, images will be cropped to the specified dimensions using center positions. |
| 371 | * |
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. |
| 374 | * @uses apply_filters() Calls 'image_resize_dimensions' on $orig_w, $orig_h, $dest_w, |
| 375 | * $dest_h and $crop to provide custom resize dimensions. |
| 376 | * |
| 377 | * @param int $orig_w Original width in pixels. |
| 378 | * @param int $orig_h Original height in pixels. |
| 379 | * @param int $dest_w New width in pixels. |
| 380 | * @param int $dest_h New height in pixels. |
| 381 | * @param bool|array $crop Optional. Whether to crop image to specified height and width or resize. |
| 382 | * An array can specify positioning of the crop area. Default false. |
| 383 | * @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 ); |
| 417 | if ( ! is_array( $crop ) || count( $crop ) !== 2 ) { |
| 418 | $crop = array( 'center', 'center' ); |
| 419 | } |
| 420 | |
| 421 | list( $x, $y ) = $crop; |
| 422 | |
| 423 | if ( 'left' === $x ) { |
| 424 | $s_x = 0; |
| 425 | } elseif ( 'right' === $x ) { |
| 426 | $s_x = $orig_w - $crop_w; |
| 427 | } else { |
| 428 | $s_x = floor( ( $orig_w - $crop_w ) / 2 ); |
| 429 | } |
| 430 | |
| 431 | if ( 'top' === $y ) { |
| 432 | $s_y = 0; |
| 433 | } elseif ( 'bottom' === $y ) { |
| 434 | $s_y = $orig_h - $crop_h; |
| 435 | } else { |
| 436 | $s_y = floor( ( $orig_h - $crop_h ) / 2 ); |
| 437 | } |