After two months hard work the new image manipulation code finally is committed to core (changeset). This all was a team effort where I’m really happy to a part from. I worked together with Mike Schroder, Japh Thomson, Kurt Payne, Andrew Nacin and Cristi Burcă.
It started on the hack day at WordCamp San Francisco where I worked mostly with Mike and Japh on it and talked with other people for getting feedback on how to do this. After the hack day I worked most of the time with Mike on getting things done and getting great feedback from Scribu and Nacin. When most of it was done Kurt helped us out with unit testing all of the code and had some great feedback as well.
The reason of the change was to allow ImageMagick to be used since it gives better images. The upside of this all is that the code is easier to read and less integrated in core so it is really easy to use inside plugins. There were also some small bugfixes to the existing code.
The most awesome part of this is that you now can write your own implementation of image handling. If you really love WPThumb then with some work I’m pretty sure you can also use that as a implementation in WordPress.
This is like the basic resize/crop example how WordPress deals with it. This will create a 100×100 image that is cropped and got saved as /path/to/image-100×100.png
$file = '/path/to/image.png'; $editor = WP_Image_Editor::get_instance( $file ); $editor->resize( 100, 100, true ); $new_image_info = $editor->save();
Change of Mime-type
You can also save it as another mime-type by doing the following ways of saving. The first one is setting the filename and it will look up the mime type from the extension. The second one you don’t need to know the filename and you just set the mime type.
$file = '/path/to/image.png'; $editor = WP_Image_Editor::get_instance( $file ); $editor->resize( 100, 100, true ); $new_image_info = $editor->save( '/path/to/image.jpg' ); // or $new_image_info = $editor->save( null, 'image/jpeg' );
Things that need to be done
There are still a lot of things to clean out before 3.5 is going to be released. Since plugin developers can create their own implementation we still need to look how we can add stuff later without breaking their implementation.
Japh is also working on getting ImageMagick/convert working. This is doing all this things by using the commandline instead of using the Imagick PHP library. I’m really curious to see how that goes.