Make WordPress Core

Ticket #19393: 19393.3.diff

File 19393.3.diff, 5.6 KB (added by DrewAPicture, 10 years ago)

doc fixes

  • src/wp-admin/includes/image.php

     
    9797                        else
    9898                                $sizes[$s]['height'] = get_option( "{$s}_size_h" ); // For default sizes set in options
    9999                        if ( isset( $_wp_additional_image_sizes[$s]['crop'] ) )
    100                                 $sizes[$s]['crop'] = intval( $_wp_additional_image_sizes[$s]['crop'] ); // For theme-added sizes
     100                                $sizes[$s]['crop'] = $_wp_additional_image_sizes[$s]['crop']; // For theme-added sizes
    101101                        else
    102102                                $sizes[$s]['crop'] = get_option( "{$s}_crop" ); // For default sizes set in options
    103103                }
  • src/wp-includes/media.php

     
    185185 *
    186186 * @since 2.9.0
    187187 *
    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.
    192205 */
    193206function add_image_size( $name, $width = 0, $height = 0, $crop = false ) {
    194207        global $_wp_additional_image_sizes;
     208
    195209        $_wp_additional_image_sizes[ $name ] = array(
    196210                'width'  => absint( $width ),
    197211                'height' => absint( $height ),
    198                 'crop'   => (bool) $crop,
     212                'crop'   => $crop,
    199213        );
    200214}
    201215
     
    342356}
    343357
    344358/**
    345  * Retrieve calculated resized dimensions for use in WP_Image_Editor.
     359 * Retrieve calculated resize dimensions for use in WP_Image_Editor.
    346360 *
    347  * Calculate dimensions and coordinates for a resized image that fits within a
    348  * specified width and height. If $crop is true, the largest matching central
    349  * portion of the image will be cropped out and resized to the required size.
     361 * Calculates dimensions and coordinates for a resized image that fits
     362 * within a specified width and height.
    350363 *
     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 *
    351374 * @since 2.5.0
    352  * @uses apply_filters() Calls 'image_resize_dimensions' on $orig_w, $orig_h, $dest_w, $dest_h and
    353  *              $crop to provide custom resize dimensions.
    354375 *
    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()`.
    361387 */
    362388function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop = false) {
    363389
     
    391417                $crop_w = round($new_w / $size_ratio);
    392418                $crop_h = round($new_h / $size_ratio);
    393419
    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                }
    396449        } else {
    397450                // don't crop, just resize using $dest_w x $dest_h as a maximum bounding box
    398451                $crop_w = $orig_w;