SlideShare a Scribd company logo
1 of 32
Download to read offline
Improved image    WordCamp Toronto - Developers
manipulation in WordPress   November 4, 2012
Marko Heijnen

• WordPress and mobile
  developer


• Working with WordPress for
  more then six years


• WordPress contributor of 3.0,
  3.3, 3.4 and 3.5


• Recent rockstar of 3.4


• Founder of WP Rockstars
Dealing with problems

• I like dealing with problems


• My first try of contributing was
  on the rewrite API


• For 3.4 I worked on the
  XML-RPC with Max Cutler &
  Westwood


• And now dealing with all the
  image manipulation API’s
What am I going to talk about

• How the current code looks like

• In short how the process went

• How the new API code looks like with the help of example
  code

• The future steps that still need to be done
How it currently looks like
Totally chaos of calls to GD functions and no way to really use it as a developer
All kinds of functions that can be used

• wp_load_image              • wp_save_image


• wp_stream_image            • wp_crop_image


• wp_save_image_file          • image_resize


• image_edit_apply_changes   • image_make_intermediate_size


• stream_preview_image
It all started at the   Working with mainly
hackday in San Francisco      Mike Schroder and Japh Thomson
The progress

• Start at hackday San Francisco on August 5

• All the coding happened on Github

• In the end we got great help from Kurt Payne with
  creating unit tests

• And obviously getting some great feedback from the
  WordPress community

• Code got committed on October 1
So what can this new API do
Default functionality

• ->resize( $max_w, $max_h, $crop );


• ->multi_resize( $sizes ); // Key is the name


• ->crop( $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs );


• ->rotate( $angle );


• ->flip( $horz, $vert );


• ->save( $destfilename, $mime_type );


• ->stream( $mime_type );
What are the default benefits

• As developer the same usage as WordPress


• Filename and Mime type control


• You can change the default mime type ( default is still jpeg )


• Better set quality support


• No more calling to GD functionality


• Imagick ( ImageMagick ) support
Examples
Let’s play with some of the code WordPress now has
Example 1
Same usage as you where using add_image_size but now you can create full
             control for which image you want to create one
The code
$file = '/path/to/image.png';


$editor = WP_Image_Editor::get_instance( $file );
$editor->resize( 300, 300, true );


$new_image_info = $editor->save(); // Save the file as /path/to/image-300x300.png
$new_image_info = $editor->save( '/path/to/image.jpg' );
$new_image_info = $editor->save( null, 'image/jpeg' ); // Save the file as /path/to/image -300x300.jpg
Info wat save() returns

 array(5) {

     ["path"]=> string(65) "/path/to/image-300x300.png"

     ["file"]=> string(20) "toronto-300x300.png"

     ["width"]=> int(300)

     ["height"]=> int(300)

     ["mime-type"]=> string(10) "image/png"

 }
Example 2
Create a crop where you want it
The code
$file = '/path/to/image.png';


$editor = WP_Image_Editor::get_instance( $file );
$editor->crop( 0, 0, 300, 300, 300, 300, false );


$new_image_info = $editor->save(); // Save the file as /path/to/image-300x300.png
Example 3
Multiple calls so lets have some play time
The code
$file = '/path/to/image.png';


$editor = WP_Image_Editor::get_instance( $file );
$editor->flip( false, true );
$editor->rotate( 30 );
$editor->crop( (1589-(960*0.7))/2, (1472-(1280*0.7))/2, 960*0.7, 1280*0.7, 300, 300, false );


$new_image_info = $editor->save(); // Save the file as /path/to/image-300x300.png
How does it work
How does it find the right editor to use
WP_Image_Editor::get_instance
	   public final static function get_instance( $path = null ) {
	   	     $implementation = self::choose_implementation();


	   	     if ( $implementation ) {
	   	     	     $editor = new $implementation( $path );
	   	     	     $loaded = $editor->load();


	   	     	     if ( is_wp_error ( $loaded ) )
	   	     	     	     return $loaded;


	   	     	     return $editor;
	   	     }


	   	     return new WP_Error( 'no_editor', __('No editor could be selected') );
	   }
WP_Image_Editor::choose_implementation();
 private final static function choose_implementation() {
 	   if ( null === self::$implementation ) {
 	   	     $request_order = array( 'WP_Image_Editor_Imagick', 'WP_Image_Editor_GD' );


 	   	     foreach ( $request_order as $editor ) {
 	   	     	     if ( ! call_user_func( array( $editor, 'test' ) ) )
 	   	     	     	     continue;


 	   	     	     self::$implementation = $editor;
 	   	     	     break;
 	   	     }
 	   }
 	   return self::$implementation;
 }
Why using the word “default”
Because you can write your own implementation
How to do this

• WP_Image_Editor::choose_implementation() has an filter
  called ‘wp_image_editors’


• With this you can add your own implementation class name to it




• When you want to use an implementation only for an certain image you can
  use the filter ‘wp_image_editor_class’
How to add your own class
 add_filter( ‘wp_image_editors’, ‘my_image_editors’ );


 function my_image_editors( $implementations ) {
 
   array_unshift( $implementations, ‘My_Image_Editor_Phpthumb’ );


 	   return $implementations;
 }


 class My_Image_Editor_Phpthumb() {
 	   //With all the needed functions
 }
What your class need to have

• ->test()

• ->load()

• ->supports_mime_type( $mime_type );

• ->resize( $max_w, $max_h, $crop );

• ->multi_resize( $sizes ); // Key is the name

• ->crop( $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs );

• ->rotate( $angle );

• ->flip( $horz, $vert );

• ->save( $destfilename, $mime_type );

• ->stream( $mime_type );
Going into the code
Anyone has a question before we do?
Whats needs to be done for 3.5

• Adding the changes I showed into core

• Add more unit tests

• Testing if there is difference between GD and Imagick by
  creating a plugin what generates images on one page

• And test till 3.5 got released over and over again
Whats needs to be done for 3.6 and later

• Creating a WP_Image class and make it easier to add a
  new image to the size array of an attachment

• Ability to have default color filters inside WordPress

• Finding a way to allow generation on the fly
Questions?
@markoheijnen - info@markoheijnen.com

More Related Content

What's hot

Shortcodes In-Depth
Shortcodes In-DepthShortcodes In-Depth
Shortcodes In-DepthMicah Wood
 
Refresh Austin - Intro to Dexy
Refresh Austin - Intro to DexyRefresh Austin - Intro to Dexy
Refresh Austin - Intro to Dexyananelson
 
Make your own wp cli command in 10min
Make your own wp cli command in 10minMake your own wp cli command in 10min
Make your own wp cli command in 10minIvelina Dimova
 
I use drupal / 我是 OO 師,我用 Drupal
I use drupal / 我是 OO 師,我用 DrupalI use drupal / 我是 OO 師,我用 Drupal
I use drupal / 我是 OO 師,我用 DrupalChris Wu
 
Prototype & jQuery
Prototype & jQueryPrototype & jQuery
Prototype & jQueryRemy Sharp
 
Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919Paul Bearne
 
jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009Remy Sharp
 
jQuery from the very beginning
jQuery from the very beginningjQuery from the very beginning
jQuery from the very beginningAnis Ahmad
 
JavaScript and jQuery Basics
JavaScript and jQuery BasicsJavaScript and jQuery Basics
JavaScript and jQuery BasicsKaloyan Kosev
 
Render API - Pavel Makhrinsky
Render API - Pavel MakhrinskyRender API - Pavel Makhrinsky
Render API - Pavel MakhrinskyDrupalCampDN
 
WordPress Theme Development for Designers
WordPress Theme Development for DesignersWordPress Theme Development for Designers
WordPress Theme Development for Designerselliotjaystocks
 

What's hot (20)

Shortcodes In-Depth
Shortcodes In-DepthShortcodes In-Depth
Shortcodes In-Depth
 
Refresh Austin - Intro to Dexy
Refresh Austin - Intro to DexyRefresh Austin - Intro to Dexy
Refresh Austin - Intro to Dexy
 
JQuery introduction
JQuery introductionJQuery introduction
JQuery introduction
 
Make your own wp cli command in 10min
Make your own wp cli command in 10minMake your own wp cli command in 10min
Make your own wp cli command in 10min
 
I use drupal / 我是 OO 師,我用 Drupal
I use drupal / 我是 OO 師,我用 DrupalI use drupal / 我是 OO 師,我用 Drupal
I use drupal / 我是 OO 師,我用 Drupal
 
Prototype & jQuery
Prototype & jQueryPrototype & jQuery
Prototype & jQuery
 
Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919Childthemes ottawa-word camp-1919
Childthemes ottawa-word camp-1919
 
jQuery PPT
jQuery PPTjQuery PPT
jQuery PPT
 
jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009jQuery Loves Developers - Oredev 2009
jQuery Loves Developers - Oredev 2009
 
jQuery from the very beginning
jQuery from the very beginningjQuery from the very beginning
jQuery from the very beginning
 
Mojolicious
MojoliciousMojolicious
Mojolicious
 
JavaScript and jQuery Basics
JavaScript and jQuery BasicsJavaScript and jQuery Basics
JavaScript and jQuery Basics
 
Render API - Pavel Makhrinsky
Render API - Pavel MakhrinskyRender API - Pavel Makhrinsky
Render API - Pavel Makhrinsky
 
Automazione quotidiana in php
Automazione quotidiana in phpAutomazione quotidiana in php
Automazione quotidiana in php
 
jQuery in 15 minutes
jQuery in 15 minutesjQuery in 15 minutes
jQuery in 15 minutes
 
Mojolicious on Steroids
Mojolicious on SteroidsMojolicious on Steroids
Mojolicious on Steroids
 
wp cli
wp cliwp cli
wp cli
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
 
jQuery Essentials
jQuery EssentialsjQuery Essentials
jQuery Essentials
 
WordPress Theme Development for Designers
WordPress Theme Development for DesignersWordPress Theme Development for Designers
WordPress Theme Development for Designers
 

Viewers also liked

Comunidade. Abuse e use dela com moderação e inteligência.
Comunidade. Abuse e use dela com moderação e inteligência.Comunidade. Abuse e use dela com moderação e inteligência.
Comunidade. Abuse e use dela com moderação e inteligência.Beto Muniz
 
Sweet Child O' Themes
Sweet Child O' ThemesSweet Child O' Themes
Sweet Child O' ThemesBreno Alves
 
WordCampBH 2015 - O mínimo essencial para o bom desempenho do seu projeto em ...
WordCampBH 2015 - O mínimo essencial para o bom desempenho do seu projeto em ...WordCampBH 2015 - O mínimo essencial para o bom desempenho do seu projeto em ...
WordCampBH 2015 - O mínimo essencial para o bom desempenho do seu projeto em ...Sergio Costa
 
Do marketplace ao WordPress - WordCamp BH 2015
Do marketplace ao WordPress -  WordCamp BH 2015Do marketplace ao WordPress -  WordCamp BH 2015
Do marketplace ao WordPress - WordCamp BH 2015Fellyph Cintra
 
Fuja do ciclo vicioso do conteúdo sem valor
Fuja do ciclo vicioso do conteúdo sem valorFuja do ciclo vicioso do conteúdo sem valor
Fuja do ciclo vicioso do conteúdo sem valorNara Grilo
 
Clean code: programando com WordPress de forma profissional
Clean code: programando com WordPress de forma profissionalClean code: programando com WordPress de forma profissional
Clean code: programando com WordPress de forma profissionalLeo Baiano
 
Wordpress search-elasticsearch
Wordpress search-elasticsearchWordpress search-elasticsearch
Wordpress search-elasticsearchTaylor Lovett
 
Como enviar newsletters no WordPress
Como enviar newsletters no WordPressComo enviar newsletters no WordPress
Como enviar newsletters no WordPressRafael Funchal
 
WordPress para Gestores de Conteúdo - WordCamp BH 2015
WordPress para Gestores de Conteúdo - WordCamp BH 2015WordPress para Gestores de Conteúdo - WordCamp BH 2015
WordPress para Gestores de Conteúdo - WordCamp BH 2015Nauweb
 
Design para WordPress- Anyssa Ferreira - WordCamp BH 2015
Design para WordPress-  Anyssa Ferreira - WordCamp BH 2015Design para WordPress-  Anyssa Ferreira - WordCamp BH 2015
Design para WordPress- Anyssa Ferreira - WordCamp BH 2015Anyssa Ferreira
 

Viewers also liked (12)

Comunidade. Abuse e use dela com moderação e inteligência.
Comunidade. Abuse e use dela com moderação e inteligência.Comunidade. Abuse e use dela com moderação e inteligência.
Comunidade. Abuse e use dela com moderação e inteligência.
 
Sweet Child O' Themes
Sweet Child O' ThemesSweet Child O' Themes
Sweet Child O' Themes
 
WordCampBH 2015 - O mínimo essencial para o bom desempenho do seu projeto em ...
WordCampBH 2015 - O mínimo essencial para o bom desempenho do seu projeto em ...WordCampBH 2015 - O mínimo essencial para o bom desempenho do seu projeto em ...
WordCampBH 2015 - O mínimo essencial para o bom desempenho do seu projeto em ...
 
Do marketplace ao WordPress - WordCamp BH 2015
Do marketplace ao WordPress -  WordCamp BH 2015Do marketplace ao WordPress -  WordCamp BH 2015
Do marketplace ao WordPress - WordCamp BH 2015
 
Método The bridge
Método The bridgeMétodo The bridge
Método The bridge
 
Teste A/B
Teste A/BTeste A/B
Teste A/B
 
Fuja do ciclo vicioso do conteúdo sem valor
Fuja do ciclo vicioso do conteúdo sem valorFuja do ciclo vicioso do conteúdo sem valor
Fuja do ciclo vicioso do conteúdo sem valor
 
Clean code: programando com WordPress de forma profissional
Clean code: programando com WordPress de forma profissionalClean code: programando com WordPress de forma profissional
Clean code: programando com WordPress de forma profissional
 
Wordpress search-elasticsearch
Wordpress search-elasticsearchWordpress search-elasticsearch
Wordpress search-elasticsearch
 
Como enviar newsletters no WordPress
Como enviar newsletters no WordPressComo enviar newsletters no WordPress
Como enviar newsletters no WordPress
 
WordPress para Gestores de Conteúdo - WordCamp BH 2015
WordPress para Gestores de Conteúdo - WordCamp BH 2015WordPress para Gestores de Conteúdo - WordCamp BH 2015
WordPress para Gestores de Conteúdo - WordCamp BH 2015
 
Design para WordPress- Anyssa Ferreira - WordCamp BH 2015
Design para WordPress-  Anyssa Ferreira - WordCamp BH 2015Design para WordPress-  Anyssa Ferreira - WordCamp BH 2015
Design para WordPress- Anyssa Ferreira - WordCamp BH 2015
 

Similar to Image manipulation in WordPress 3.5

10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)arcware
 
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)Mike Schinkel
 
Как получить чёрный пояс по WordPress?
Как получить чёрный пояс по WordPress?Как получить чёрный пояс по WordPress?
Как получить чёрный пояс по WordPress?Yevhen Kotelnytskyi
 
Как получить чёрный пояс по WordPress? v2.0
Как получить чёрный пояс по WordPress? v2.0Как получить чёрный пояс по WordPress? v2.0
Как получить чёрный пояс по WordPress? v2.0Yevhen Kotelnytskyi
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For BeginnersJonathan Wage
 
WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1Yoav Farhi
 
Becoming a better WordPress Developer
Becoming a better WordPress DeveloperBecoming a better WordPress Developer
Becoming a better WordPress DeveloperJoey Kudish
 
Using Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkUsing Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkDirk Haun
 
[WLDN] Supercharging word press development in 2018
[WLDN] Supercharging word press development in 2018[WLDN] Supercharging word press development in 2018
[WLDN] Supercharging word press development in 2018Adam Tomat
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐいHisateru Tanaka
 
WordPress Plugin development
WordPress Plugin developmentWordPress Plugin development
WordPress Plugin developmentMostafa Soufi
 
Laying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme developmentLaying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme developmentTammy Hart
 
WordPress for developers - phpday 2011
WordPress for developers -  phpday 2011WordPress for developers -  phpday 2011
WordPress for developers - phpday 2011Maurizio Pelizzone
 
Gae Meets Django
Gae Meets DjangoGae Meets Django
Gae Meets Djangofool2nd
 
Getting to The Loop - London Wordpress Meetup July 28th
Getting to The Loop - London Wordpress Meetup  July 28thGetting to The Loop - London Wordpress Meetup  July 28th
Getting to The Loop - London Wordpress Meetup July 28thChris Adams
 
Drupal vs WordPress
Drupal vs WordPressDrupal vs WordPress
Drupal vs WordPressWalter Ebert
 
Writing extensible Word press-plugins
Writing extensible Word press-pluginsWriting extensible Word press-plugins
Writing extensible Word press-pluginsAllenSnook
 

Similar to Image manipulation in WordPress 3.5 (20)

10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
10 Things Every Plugin Developer Should Know (WordCamp Atlanta 2013)
 
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
Hardcore URL Routing for WordPress - WordCamp Atlanta 2014 (PPT)
 
Как получить чёрный пояс по WordPress?
Как получить чёрный пояс по WordPress?Как получить чёрный пояс по WordPress?
Как получить чёрный пояс по WordPress?
 
Как получить чёрный пояс по WordPress? v2.0
Как получить чёрный пояс по WordPress? v2.0Как получить чёрный пояс по WordPress? v2.0
Как получить чёрный пояс по WordPress? v2.0
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
 
WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1WordPress Developers Israel Meetup #1
WordPress Developers Israel Meetup #1
 
Becoming a better WordPress Developer
Becoming a better WordPress DeveloperBecoming a better WordPress Developer
Becoming a better WordPress Developer
 
Using Geeklog as a Web Application Framework
Using Geeklog as a Web Application FrameworkUsing Geeklog as a Web Application Framework
Using Geeklog as a Web Application Framework
 
[WLDN] Supercharging word press development in 2018
[WLDN] Supercharging word press development in 2018[WLDN] Supercharging word press development in 2018
[WLDN] Supercharging word press development in 2018
 
関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい関西PHP勉強会 php5.4つまみぐい
関西PHP勉強会 php5.4つまみぐい
 
WordCamp Praga 2015
WordCamp Praga 2015WordCamp Praga 2015
WordCamp Praga 2015
 
Seven deadly theming sins
Seven deadly theming sinsSeven deadly theming sins
Seven deadly theming sins
 
WordPress Plugin development
WordPress Plugin developmentWordPress Plugin development
WordPress Plugin development
 
Laying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme developmentLaying the proper foundation for plugin and theme development
Laying the proper foundation for plugin and theme development
 
WordPress for developers - phpday 2011
WordPress for developers -  phpday 2011WordPress for developers -  phpday 2011
WordPress for developers - phpday 2011
 
QA for PHP projects
QA for PHP projectsQA for PHP projects
QA for PHP projects
 
Gae Meets Django
Gae Meets DjangoGae Meets Django
Gae Meets Django
 
Getting to The Loop - London Wordpress Meetup July 28th
Getting to The Loop - London Wordpress Meetup  July 28thGetting to The Loop - London Wordpress Meetup  July 28th
Getting to The Loop - London Wordpress Meetup July 28th
 
Drupal vs WordPress
Drupal vs WordPressDrupal vs WordPress
Drupal vs WordPress
 
Writing extensible Word press-plugins
Writing extensible Word press-pluginsWriting extensible Word press-plugins
Writing extensible Word press-plugins
 

More from Marko Heijnen

Custom coded projects
Custom coded projectsCustom coded projects
Custom coded projectsMarko Heijnen
 
Security, more important than ever!
Security, more important than ever!Security, more important than ever!
Security, more important than ever!Marko Heijnen
 
My Contributor Story
My Contributor StoryMy Contributor Story
My Contributor StoryMarko Heijnen
 
WooCommerce & Apple TV
WooCommerce & Apple TVWooCommerce & Apple TV
WooCommerce & Apple TVMarko Heijnen
 
The moment my site got hacked - WordCamp Sofia
The moment my site got hacked - WordCamp SofiaThe moment my site got hacked - WordCamp Sofia
The moment my site got hacked - WordCamp SofiaMarko Heijnen
 
Mijn site beveiliging
Mijn site beveiligingMijn site beveiliging
Mijn site beveiligingMarko Heijnen
 
The moment my site got hacked
The moment my site got hackedThe moment my site got hacked
The moment my site got hackedMarko Heijnen
 
My complicated WordPress site
My complicated WordPress siteMy complicated WordPress site
My complicated WordPress siteMarko Heijnen
 
Node.js to the rescue
Node.js to the rescueNode.js to the rescue
Node.js to the rescueMarko Heijnen
 
Protecting your site by detection
Protecting your site by detectionProtecting your site by detection
Protecting your site by detectionMarko Heijnen
 
GlotPress aka translate.wordpress.org
GlotPress aka translate.wordpress.orgGlotPress aka translate.wordpress.org
GlotPress aka translate.wordpress.orgMarko Heijnen
 
Writing clean and maintainable code
Writing clean and maintainable codeWriting clean and maintainable code
Writing clean and maintainable codeMarko Heijnen
 
Extending WordPress as a pro
Extending WordPress as a proExtending WordPress as a pro
Extending WordPress as a proMarko Heijnen
 
Let's create a multilingual site in WordPress
Let's create a multilingual site in WordPressLet's create a multilingual site in WordPress
Let's create a multilingual site in WordPressMarko Heijnen
 
Bootstrapping your plugin
Bootstrapping your pluginBootstrapping your plugin
Bootstrapping your pluginMarko Heijnen
 
The development and future of GlotPress
The development and future of GlotPressThe development and future of GlotPress
The development and future of GlotPressMarko Heijnen
 
Why Javascript matters
Why Javascript mattersWhy Javascript matters
Why Javascript mattersMarko Heijnen
 
The code history of WordPress
The code history of WordPressThe code history of WordPress
The code history of WordPressMarko Heijnen
 
Building plugins like a pro
Building plugins like a proBuilding plugins like a pro
Building plugins like a proMarko Heijnen
 
Perfect your images using WordPress - WordCamp Europe 2013
Perfect your images using WordPress - WordCamp Europe 2013Perfect your images using WordPress - WordCamp Europe 2013
Perfect your images using WordPress - WordCamp Europe 2013Marko Heijnen
 

More from Marko Heijnen (20)

Custom coded projects
Custom coded projectsCustom coded projects
Custom coded projects
 
Security, more important than ever!
Security, more important than ever!Security, more important than ever!
Security, more important than ever!
 
My Contributor Story
My Contributor StoryMy Contributor Story
My Contributor Story
 
WooCommerce & Apple TV
WooCommerce & Apple TVWooCommerce & Apple TV
WooCommerce & Apple TV
 
The moment my site got hacked - WordCamp Sofia
The moment my site got hacked - WordCamp SofiaThe moment my site got hacked - WordCamp Sofia
The moment my site got hacked - WordCamp Sofia
 
Mijn site beveiliging
Mijn site beveiligingMijn site beveiliging
Mijn site beveiliging
 
The moment my site got hacked
The moment my site got hackedThe moment my site got hacked
The moment my site got hacked
 
My complicated WordPress site
My complicated WordPress siteMy complicated WordPress site
My complicated WordPress site
 
Node.js to the rescue
Node.js to the rescueNode.js to the rescue
Node.js to the rescue
 
Protecting your site by detection
Protecting your site by detectionProtecting your site by detection
Protecting your site by detection
 
GlotPress aka translate.wordpress.org
GlotPress aka translate.wordpress.orgGlotPress aka translate.wordpress.org
GlotPress aka translate.wordpress.org
 
Writing clean and maintainable code
Writing clean and maintainable codeWriting clean and maintainable code
Writing clean and maintainable code
 
Extending WordPress as a pro
Extending WordPress as a proExtending WordPress as a pro
Extending WordPress as a pro
 
Let's create a multilingual site in WordPress
Let's create a multilingual site in WordPressLet's create a multilingual site in WordPress
Let's create a multilingual site in WordPress
 
Bootstrapping your plugin
Bootstrapping your pluginBootstrapping your plugin
Bootstrapping your plugin
 
The development and future of GlotPress
The development and future of GlotPressThe development and future of GlotPress
The development and future of GlotPress
 
Why Javascript matters
Why Javascript mattersWhy Javascript matters
Why Javascript matters
 
The code history of WordPress
The code history of WordPressThe code history of WordPress
The code history of WordPress
 
Building plugins like a pro
Building plugins like a proBuilding plugins like a pro
Building plugins like a pro
 
Perfect your images using WordPress - WordCamp Europe 2013
Perfect your images using WordPress - WordCamp Europe 2013Perfect your images using WordPress - WordCamp Europe 2013
Perfect your images using WordPress - WordCamp Europe 2013
 

Recently uploaded

DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 

Recently uploaded (20)

DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 

Image manipulation in WordPress 3.5

  • 1. Improved image WordCamp Toronto - Developers manipulation in WordPress November 4, 2012
  • 2. Marko Heijnen • WordPress and mobile developer • Working with WordPress for more then six years • WordPress contributor of 3.0, 3.3, 3.4 and 3.5 • Recent rockstar of 3.4 • Founder of WP Rockstars
  • 3. Dealing with problems • I like dealing with problems • My first try of contributing was on the rewrite API • For 3.4 I worked on the XML-RPC with Max Cutler & Westwood • And now dealing with all the image manipulation API’s
  • 4. What am I going to talk about • How the current code looks like • In short how the process went • How the new API code looks like with the help of example code • The future steps that still need to be done
  • 5. How it currently looks like Totally chaos of calls to GD functions and no way to really use it as a developer
  • 6. All kinds of functions that can be used • wp_load_image • wp_save_image • wp_stream_image • wp_crop_image • wp_save_image_file • image_resize • image_edit_apply_changes • image_make_intermediate_size • stream_preview_image
  • 7.
  • 8. It all started at the Working with mainly hackday in San Francisco Mike Schroder and Japh Thomson
  • 9. The progress • Start at hackday San Francisco on August 5 • All the coding happened on Github • In the end we got great help from Kurt Payne with creating unit tests • And obviously getting some great feedback from the WordPress community • Code got committed on October 1
  • 10. So what can this new API do
  • 11. Default functionality • ->resize( $max_w, $max_h, $crop ); • ->multi_resize( $sizes ); // Key is the name • ->crop( $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs ); • ->rotate( $angle ); • ->flip( $horz, $vert ); • ->save( $destfilename, $mime_type ); • ->stream( $mime_type );
  • 12. What are the default benefits • As developer the same usage as WordPress • Filename and Mime type control • You can change the default mime type ( default is still jpeg ) • Better set quality support • No more calling to GD functionality • Imagick ( ImageMagick ) support
  • 13. Examples Let’s play with some of the code WordPress now has
  • 14. Example 1 Same usage as you where using add_image_size but now you can create full control for which image you want to create one
  • 15. The code $file = '/path/to/image.png'; $editor = WP_Image_Editor::get_instance( $file ); $editor->resize( 300, 300, true ); $new_image_info = $editor->save(); // Save the file as /path/to/image-300x300.png $new_image_info = $editor->save( '/path/to/image.jpg' ); $new_image_info = $editor->save( null, 'image/jpeg' ); // Save the file as /path/to/image -300x300.jpg
  • 16. Info wat save() returns array(5) { ["path"]=> string(65) "/path/to/image-300x300.png" ["file"]=> string(20) "toronto-300x300.png" ["width"]=> int(300) ["height"]=> int(300) ["mime-type"]=> string(10) "image/png" }
  • 17. Example 2 Create a crop where you want it
  • 18. The code $file = '/path/to/image.png'; $editor = WP_Image_Editor::get_instance( $file ); $editor->crop( 0, 0, 300, 300, 300, 300, false ); $new_image_info = $editor->save(); // Save the file as /path/to/image-300x300.png
  • 19. Example 3 Multiple calls so lets have some play time
  • 20. The code $file = '/path/to/image.png'; $editor = WP_Image_Editor::get_instance( $file ); $editor->flip( false, true ); $editor->rotate( 30 ); $editor->crop( (1589-(960*0.7))/2, (1472-(1280*0.7))/2, 960*0.7, 1280*0.7, 300, 300, false ); $new_image_info = $editor->save(); // Save the file as /path/to/image-300x300.png
  • 21. How does it work How does it find the right editor to use
  • 22. WP_Image_Editor::get_instance public final static function get_instance( $path = null ) { $implementation = self::choose_implementation(); if ( $implementation ) { $editor = new $implementation( $path ); $loaded = $editor->load(); if ( is_wp_error ( $loaded ) ) return $loaded; return $editor; } return new WP_Error( 'no_editor', __('No editor could be selected') ); }
  • 23. WP_Image_Editor::choose_implementation(); private final static function choose_implementation() { if ( null === self::$implementation ) { $request_order = array( 'WP_Image_Editor_Imagick', 'WP_Image_Editor_GD' ); foreach ( $request_order as $editor ) { if ( ! call_user_func( array( $editor, 'test' ) ) ) continue; self::$implementation = $editor; break; } } return self::$implementation; }
  • 24. Why using the word “default”
  • 25. Because you can write your own implementation
  • 26. How to do this • WP_Image_Editor::choose_implementation() has an filter called ‘wp_image_editors’ • With this you can add your own implementation class name to it • When you want to use an implementation only for an certain image you can use the filter ‘wp_image_editor_class’
  • 27. How to add your own class add_filter( ‘wp_image_editors’, ‘my_image_editors’ ); function my_image_editors( $implementations ) { array_unshift( $implementations, ‘My_Image_Editor_Phpthumb’ ); return $implementations; } class My_Image_Editor_Phpthumb() { //With all the needed functions }
  • 28. What your class need to have • ->test() • ->load() • ->supports_mime_type( $mime_type ); • ->resize( $max_w, $max_h, $crop ); • ->multi_resize( $sizes ); // Key is the name • ->crop( $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs ); • ->rotate( $angle ); • ->flip( $horz, $vert ); • ->save( $destfilename, $mime_type ); • ->stream( $mime_type );
  • 29. Going into the code Anyone has a question before we do?
  • 30. Whats needs to be done for 3.5 • Adding the changes I showed into core • Add more unit tests • Testing if there is difference between GD and Imagick by creating a plugin what generates images on one page • And test till 3.5 got released over and over again
  • 31. Whats needs to be done for 3.6 and later • Creating a WP_Image class and make it easier to add a new image to the size array of an attachment • Ability to have default color filters inside WordPress • Finding a way to allow generation on the fly