Function Reference/image downsize
(Add your language)
Scale an image to fit a particular size (such as
$max_/$min_width for the Reserved Names will always be what you defined under "admin UI" » "Settings" » "Media". For detail, please refer to image_constrain_size_for_editor().
The URL might be the original image, or it might be a resized version. This function won't create a new resized copy, it will just return an already resized one if it exists.
- (integer) (required) The ID of the image.
- Default: None
- (string) (optional) Size of image. It can be thumbnail or medium .
- Default: medium
- False on failure, array on success. Array with image url, width, height, and whether is intermediate size ($is_intermediate), in that order is returned on success is returned. $is_intermediate is true if $url is a resized image, false if it is the original.
image_downsize() is located in
Add a function to select medium attachment images
Maybe you already know wp_get_attachment_thumb_url();. Now I'm showing how to do the same thing to return the url for the medium sized attachment.
function wp_get_attachment_medium_url( $id )
$medium_array = image_downsize( $id, 'medium' );
$medium_path = $medium_array;
$id is the ID of the attachment
This can be really useful for plugins like WP-Choose-Thumb. With this function you can get the medium sized previews.