Today I was reading trough the ImageMagick ChangeLog and noticed an interesting entry. “Add support for liquid rescaling”. I rushed to check the MagickWand API docs and there it was: MagickLiquidRescaleImage! After about ten minutes of hacking the Imagick support was done. Needless to say; I was excited
For those who don’t know what seam carving is check the demo here. More detailed information about the algorithm can be found here: “Seam Carving for Content-Aware Image Resizing” by Shai Avidan and Ariel Shamir
To use this functionality you need to install at least ImageMagick 6.3.8-2 and liblqr. Remember to pass –with-lqr to ImageMagick configuration line. You can get liblqr here: http://liblqr.wikidot.com/. The Imagick side of the functionality should appear in the CVS today if everything goes as planned.
Here is a really simple example just to illustrate the results of the operation. The parameters might be far from optimal (didn’t do much testing yet). The original dimensions of image are 500×375 and the resulting size is 500×200.
Update: the functionality is pending until license issues are solved.
- /* Create new object */
- $im = new Imagick( 'test.jpg' );
- /* Scale down */
- $im->liquidRescaleImage( 500, 200, 3, 25 );
- /* Display */
- header( 'Content-Type: image/jpg' );
- echo $im;
The original image by flickr/jennconspiracy
And the result:
Update. On kenrick’s request here is an image which is scaled down to 300×300