WordPress.org

Ready to get started?Download WordPress

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/image resize


This function has been deprecated. That means it has been replaced by a new function or is no longer supported, and may be removed from future versions. All code that uses this function should be converted to use its replacement if one exists. See also wp-includes/deprecated.php. Use any of these functions instead.

This function has been deprecated in favor of WP_Image_Editor.

Contents

Description

Scale down an image to fit a particular size and save a new copy of the image.

The PNG transparency will be preserved using the function, as well as the image type. If the file going in is PNG, then the resized image is going to be PNG. The only supported image types are PNG, GIF, and JPEG.

Some functionality requires API to exist, so some PHP version may lose out support. This is not the fault of WordPress (where functionality is downgraded, not actual defects), but of your PHP version.

Usage

<?php image_resize$file$max_w$max_h$crop$suffix$dest_path$jpeg_quality ); ?>

Parameters

$file
(string) (required) Image file path.
Default: None
$max_w
(int) (required) Maximum width to resize to.
Default: None
$max_h
(int) (required) Maximum height to resize to.
Default: None
$crop
(boolean) (optional) Optional. Whether to crop image or resize.
Default: false
$suffix
(string) (optional) Optional. File Suffix.
Default: null
$dest_path
(string) (optional) Optional. New image file path.
Default: null
$jpeg_quality
(int) (optional) Optional, default is 90. Image quality percentage.
Default: 90

Return Values

(mixed) 
WP_Error on failure. String with new destination path.

Change Log

Source File

image_resize() is located in wp-includes/media.php

Related

See also index of Function Reference and index of Template Tags.