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 500x375 and the resulting size is 500x200.

Update: the functionality is pending until license issues are solved.

PHP:
  1. <?php
  2.  
  3. /* Create new object */
  4. $im = new Imagick( 'test.jpg' );
  5.  
  6. /* Scale down */
  7. $im->liquidRescaleImage( 500, 200, 3, 25 );
  8.  
  9. /* Display */
  10. header( 'Content-Type: image/jpg' );
  11. echo $im;
  12.  
  13. ?>

The original image by flickr/jennconspiracy

result

And the result:

result

Update. On kenrick's request here is an image which is scaled down to 300x300

result2