wp_get_image_editor()
Returns a WP_Image_Editor instance and loads file into it.
Hooks from the function
Return
WP_Image_Editor|WP_Error
. The WP_Image_Editor object on success, a WP_Error object otherwise.
Usage
wp_get_image_editor( $path, $args );
- $path(string) (required)
- Path to the file to load.
- $args(array)
- Additional arguments for retrieving the image editor.
Default: empty array
Examples
#1 Create a thumbnail of the image
Suppose we have an image /wp-content/uploads/2014/02/uka.png
(lying on our server). This example shows how to create a thumbnail of this image with the class WP_Image_Editor`:
// load the object $image = wp_get_image_editor( $_SERVER['DOCUMENT_ROOT'].'/wp-content/uploads/2014/02/uka.png' ); // you can specify a URL instead of an absolute path: // $image = wp_get_image_editor( 'http://wp-kama.ru/wp-content/uploads/2014/02/uka.png' ); // process the picture if ( ! is_wp_error( $image ) ) { // rotate the picture 90 degrees $image->rotate( 90 ); // reduce it to size 80x80 $image->resize( 80, 80, true ); // save it in the root of the site as new_image.png $image->save( $_SERVER['DOCUMENT_ROOT'].'/new_image.png' ); }
Changelog
Since 3.5.0 | Introduced. |