image_resize_dimensions

函数


image_resize_dimensions ( $orig_w, $orig_h, $dest_w, $dest_h, $crop = false )
参数
  • (int)
    $orig_w
    Original width in pixels.
    Required:
  • (int)
    $orig_h
    Original height in pixels.
    Required:
  • (int)
    $dest_w
    New width in pixels.
    Required:
  • (int)
    $dest_h
    New height in pixels.
    Required:
  • (bool|array)
    $crop
    Optional. Whether to crop image to specified width and height or resize. An array can specify positioning of the crop area. Default false.
    Required:
    Default: false
返回值
  • (array|false) Returned array matches parameters for `imagecopyresampled()`. False on failure.
定义位置
  • wp-includes/media.php
    , line 530
引入
2.5.0
弃用

Retrieves calculated resize dimensions for use in WP_Image_Editor.

Calculates dimensions and coordinates for a resized image that fits
within a specified width and height.

Cropping behavior is dependent on the value of $crop:
1. If false (default), images will not be cropped.
2. If an array in the form of array( x_crop_position, y_crop_position ):
– x_crop_position accepts ‘left’ ‘center’, or ‘right’.
– y_crop_position accepts ‘top’, ‘center’, or ‘bottom’.
Images will be cropped to the specified dimensions within the defined crop area.
3. If true, images will be cropped to the specified dimensions using center positions.

function image_resize_dimensions( $orig_w, $orig_h, $dest_w, $dest_h, $crop = false ) {

	if ( $orig_w