Slide 1

Slide 1 text

WP_Image_Editor or How I Learned to Stop TimThumbing and Love the Core. WordCamp Vancouver 2013 Mike Schroder (DH-Shredder) @GetSource - http://www.getsource.net

Slide 2

Slide 2 text

Who Am I? • Mike Schroder, a.k.a DH-Shredder, a.k.a. @GetSource • Third Culture Kid, enjoy Coffee & Sailing • WordPress 3.5 Recent Rockstar and WP-CLI Contributor • Co-Author of WP_Image_Editor • Happy DreamHost Employee

Slide 3

Slide 3 text

Previous to 3.5, GD was used directly.

Slide 4

Slide 4 text

This meant a mess of functions for Developers.

Slide 5

Slide 5 text

Image Manipulation abstracted.

Slide 6

Slide 6 text

WP_Image_Editor Centralized way to read an image file directly, manipulate it, and output

Slide 7

Slide 7 text

3.5 comes with Editors for GD and Imagick support

Slide 8

Slide 8 text

With Imagick, this means support for Color Profiles

Slide 9

Slide 9 text

GD Imagick

Slide 10

Slide 10 text

GD Imagick GD

Slide 11

Slide 11 text

GD Imagick Imagick

Slide 12

Slide 12 text

GD Imagick GD

Slide 13

Slide 13 text

GD Imagick Imagick

Slide 14

Slide 14 text

What’s the catch? Deprecated filters due to GD abstraction

Slide 15

Slide 15 text

What’s it missing? Centralized way to read an image attachment from the database and manage its sizes and properties

Slide 16

Slide 16 text

That’s WP_Image. ...Hopefully

Slide 17

Slide 17 text

Okay. So, what can I do with it?

Slide 18

Slide 18 text

Resize, Batch Resize, Crop, Flip, Rotate, and Stream. wp-includes/class-wp-image-editor.php

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

// Get instance of WP_Image_Editor selected by WordPress $image = wp_get_image_editor( '/path/to/cool_image.jpg' ); // Returns WP_Error on failure, so check. if ( ! is_wp_error( $image ) ) { // Rotate in 90 degree increments, for now. $image->rotate( 90 ); // Thumbnail, and crop. $image->resize( 300, 300, true ); // Uses extension for type, unless optional mime parameter is used. $image->save( 'new_image.gif' ); ! // Types only limited by Editor and what WordPress allows for uploads. if ( $image->supports_mime_type( 'application/pdf' ) ) $image->stream( 'application/pdf' ); } Time for an Example!

Slide 21

Slide 21 text

To load an attachment... No current alternative to load_image_to_edit(), so: wp_get_image_editor( _load_image_to_edit_path( $post_id ) );

Slide 22

Slide 22 text

Extend to create your own image-manip engines or functions.

Slide 23

Slide 23 text

You can extend Imagick for everyone’s favorite filter:

Slide 24

Slide 24 text

Sepia!

Slide 25

Slide 25 text

Sepia makes the world go brown.

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

Editor Engine Examples • GD: wp-includes/class-wp-image-editor-gd.php • Imagick: wp-includes/class-wp-image-editor-imagick.php • Gmagick: http://wordpress.org/extend/plugins/gmagick/

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

More Resources! • http://make.wordpress.org/core/2012/12/06/wp_image_editor-is-incoming/ • http://markoheijnen.com/wordpress-new-image-manipulation/ • http://xref.wordpress.org/trunk/WordPress/Image_Editor/ WP_Image_Editor.html • https://github.com/getsource/imagick-sepia/ • https://github.com/humanmade/WPThumb/ Mike Schroder (DH-Shredder) @GetSource - http://www.getsource.net