WordPress.org

Ready to get started?Download WordPress

Codex

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

Difference between revisions of "Function Reference/wp get image editor"

(3.5 – Introduce wp_get_image_editor. Add parameters, return, source file)
Line 1: Line 1:
 
== Description ==
 
== Description ==
+
This function is the main function what you use when you want to edit an image by url. It returns a [[Class_Reference/WP_Image_Editor|WP_Image_Editor]] instance and loads a file into it. With that you can manipulate an image by calling methods on it. For more information on that you can read: [[Class_Reference/WP_Image_Editor|WP_Image_Editor]].
Returns a [[Class_Reference/WP_Image_Editor|WP_Image_Editor]] instance and loads a file into it.
 
   
 
== Usage ==
 
== Usage ==
  +
  +
%%%<?php wp_get_image_editor( $path, $args ); ?> %%%
   
 
== Parameters ==
 
== Parameters ==
   
 
{{Parameter|$path|string|Path to file to load}}
 
{{Parameter|$path|string|Path to file to load}}
{{Parameter|$args|array|Additional data. Accepts <tt>mime_type</tt>, Methods ,etc}}
+
{{Parameter|$args|array|Additional data. Accepts <tt>mime_type</tt>, <tt>methods</tt> }}
   
 
== Return ==
 
== Return ==
Line 14: Line 16:
   
 
== Examples ==
 
== Examples ==
  +
<pre>
  +
$image = wp_get_image_editor( 'cool_image.jpg' );
  +
if ( ! is_wp_error( $image ) ) {
  +
$image->rotate( 90 );
  +
$image->resize( 300, 300, true );
  +
$image->save( 'new_image.jpg' );
  +
}
  +
</pre>
   
 
== Change Log ==
 
== Change Log ==

Revision as of 20:29, 15 December 2012

Description

This function is the main function what you use when you want to edit an image by url. It returns a WP_Image_Editor instance and loads a file into it. With that you can manipulate an image by calling methods on it. For more information on that you can read: WP_Image_Editor.

Usage

<?php wp_get_image_editor$path$args ); ?> 

Parameters

$path
(string) (required) Path to file to load
Default: None
$args
(array) (required) Additional data. Accepts mime_type, methods
Default: None

Return

(mixed) 
WP_Image_Editor object or WP_Error on failure

Examples

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

Change Log

Source File

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

Related