WP_Image_Editor
- Since
- 3.5.0
- Source
wp-includes/class-wp-image-editor.php:14
Base image editor class from which implementations extend
Compatibility
- WordPress
- since 3.5.0
- 6.7.7
- 6.8.8
- 6.9.7
- 7.0.4
- 7.1.0
Present in every tracked release (6.7.7 to 7.1.0).
Hooks and filters fired · 4
Every hook that fires from inside WP_Image_Editor, in the order it appears in the class, grouped by the method that fires it.
WP_Image_Editor::set_quality()
- apply_filters( wp_editor_set_quality )filter line 267
- apply_filters( jpeg_quality )filter line 286
Properties · 7
$fileprotected$sizeprotected$mime_typeprotected$output_mime_typeprotected$default_mime_typeprotected$qualityprotected$default_qualityprotected
Methods · 23
- __construct()Each instance handles a single file.
- test()Checks to see if current environment supports the editor chosen.
- supports_mime_type()Checks to see if editor supports the mime-type specified.
- load()Loads image from $this->file into editor.
- save()Saves current image to file.
- resize()Resizes current image.
- multi_resize()Resize multiple images from a single source.
- crop()Crops Image.
- rotate()Rotates current image counter-clockwise by $angle.
- flip()Flips current image.
- stream()Streams current image to browser.
- get_size()Gets dimensions of image.
- update_size()Sets current image size.
- get_quality()Gets the Image Compression quality on a 1-100% scale.
- set_quality()Sets Image Compression quality on a 1-100% scale.
- get_default_quality()Returns the default compression quality setting for the mime type.
- get_output_format()Returns preferred mime-type and extension based on provided file's extension and mime, or current file's extension and mime.
- generate_filename()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.
- maybe_exif_rotate()Check if a JPEG image has EXIF Orientation tag and rotate it if needed.
- make_image()Either calls editor's save function or handles file as a stream.
- get_mime_type()Returns first matched mime-type from extension, as mapped from wp_get_mime_types()
- get_extension()Returns first matched extension from Mime-type, as mapped from wp_get_mime_types()
Source code
#[AllowDynamicProperties]abstract class WP_Image_Editor { protected $file = null; protected $size = null; protected $mime_type = null; protected $output_mime_type = null; protected $default_mime_type = 'image/jpeg'; protected $quality = false; // Deprecated since 5.8.1. See get_default_quality() below. protected $default_quality = 82; /** * Each instance handles a single file. * * @param string $file Path to the file to load. */ public function __construct( $file ) { $this->file = $file; } /** * Checks to see if current environment supports the editor chosen. * Must be overridden in a subclass. * * @since 3.5.0 * * @abstract * * @param array $args * @return bool */ public static function test( $args = array() ) { return false; } /** * Checks to see if editor supports the mime-type specified. * Must be overridden in a subclass. * * @since 3.5.0 * * @abstract * * @param string $mime_type * @return bool */ public static function supports_mime_type( $mime_type ) { return false; } /** * Loads image from $this->file into editor. * * @since 3.5.0 * @abstract * * @return true|WP_Error True if loaded; WP_Error on failure. */ abstract public function load(); /** * Saves current image to file. * * @since 3.5.0 * @since 6.0.0 The `$filesize` value was added to the returned array. * @abstract * * @param string $destfilename Optional. Destination filename. Default null. * @param string $mime_type Optional. The mime-type. Default null. * @return array|WP_Error { * Array on success or WP_Error if the file failed to save. * * @type string $path Path to the image file. * @type string $file Name of the image file. * @type int $width Image width. * @type int $height Image height. * @type string $mime-type The mime type of the image. * @type int $filesize File size of the image. * }Changelog
Introduced in 3.5.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 6.7.7 tag, from
src/wp-includes/class-wp-image-editor.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.