Upgrade to Pro — share decks privately, control downloads, hide ads and more …

WP_Image_Editor, or How I Learned to Stop TimThumbing and Love the Core

WP_Image_Editor, or How I Learned to Stop TimThumbing and Love the Core

Learn about some of the new features for editing images and creating image manipulation engines within WordPress 3.5+

Lightning Talk presented at WordCamp Vancouver 2013 by Mike Schroder

Mike Schroder

August 17, 2013
Tweet

More Decks by Mike Schroder

Other Decks in Programming

Transcript

  1. 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
  2. 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
  3. What’s it missing? Centralized way to read an image attachment

    from the database and manage its sizes and properties
  4. // 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!
  5. To load an attachment... No current alternative to load_image_to_edit(), so:

    wp_get_image_editor( _load_image_to_edit_path( $post_id ) );