WordPress.org

Ready to get started?Download WordPress

Codex

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

Class Reference/WP Image Editor

Description

WP_Image_Editor is a class defined in wp-includes/class-wp-image-editor.php that is an abstract class, so it can't be called directly. It is used for implementations like WP_Image_Editor_GD and WP_Image_Editor_Imagick. It has some base functionality that can be used by those implementations.

Interacting with WP_Image_Editor

Usage

$image = wp_get_image_editor( 'cool_image.jpg' ); // Return an implementation that extends <tt>WP_Image_Editor</tt>

if ( ! is_wp_error( $image ) ) {
    $image->rotate( 90 );
    $image->resize( 300, 300, true );
    $image->save( 'new_image.jpg' );
}

Methods and Properties

You shouldn't call an implementation directly. Instead, use wp_get_image_editor(), which looks at which implementation is the best.

Methods

(An ampersand (&) before a method name indicates it returns by reference.)

supports_mime_type( $mime_type )
Checks to see if editor supports the mime-type specified.
save( $destfilename = null, $mime_type = null )
Saves current image to file.
resize( $max_w, $max_h, $crop = false )
Resizes current image.
Crop value:
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.
multi_resize( $sizes );
Processes current image and saves to disk multiple sizes from single source.
crop( $src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false )
Crops Image.
rotate( $angle )
Rotates current image counter-clockwise by $angle.
flip( $horz, $vert )
Flips current image on the horizontal or vertical axis.
stream( $mime_type = null )
Streams current image to browser.
get_size()
Gets dimensions of image as an array with keys 'width' and 'height'.
update_size( $width = null, $height = null )
Sets current image size.
set_quality( $quality )
Sets Image Compression quality on a 1-100% scale as an integer (1-100). Default quality defined in WP_Image_Editor class is 90.
get_output_format( $filename = null, $mime_type = null )
Returns preferred mime-type and extension based on provided file's extension and mime, or current file's extension and mime. Will default to `$this->default_mime_type` if requested is not supported. Provides corrected filename only if filename is provided.
generate_filename( $suffix = null, $dest_path = null, $extension = null )
Builds an output filename based on current file, and adding proper suffix.
get_suffix()
Builds and returns proper suffix for file based on height and width.
make_image( $filename, $function, $arguments )
Either calls editor's save function or handles file as a stream.
get_mime_type( $extension = null )
Returns first matched mime-type from extension, as mapped from wp_get_mime_types().
get_extension( $mime_type = null )
Returns first matched extension from Mime-type, as mapped from wp_get_mime_types().

Filters

Source File

WP_Image_Editor() is located in wp-includes/class-wp-image-editor.php.

Resources

Related

Change Log

This article is marked as in need of editing. You can help Codex by editing it.