image_resize_dimensions

SummerySummery

Retrieves calculated resize dimensions for use in WP_Image_Editor.

Syntax

image_resize_dimensions( int $orig_w, int $orig_h, int $dest_w, int $dest_h, bool|array $crop = false )

DescriptionDescription

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.

ParametersParameters

$orig_w

(int) (Required) Original width in pixels.

$orig_h

(int) (Required) Original height in pixels.

$dest_w

(int) (Required) New width in pixels.

$dest_h

(int) (Required) New height in pixels.

$crop

(bool|array) (Optional) Whether to crop image to specified width and height or resize. An array can specify positioning of the crop area.

Default value: false

ReturnReturn

(array|false) Returned array matches parameters for imagecopyresampled(). False on failure.

SourceSource

File: wp-includes/media.php


			

ChangelogChangelog

Changelog
Version Description
2.5.0 Introduced.
Scroll to Top