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.
- <?php
- /* 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

#1 by Michelle Bristol on May 1, 2011 - 3:02 pm
Quote
Just interested in what sort of practical uses you have seen for this. I can see it be useful for rotating different images that all need to fit into the same size box. Anything else?
#2 by College Degree Online on July 22, 2011 - 12:01 pm
Quote
Wow, these tweaks are really helpful in my blog, I no longer need to adjust my image sizes just to fit the width of my content.
#3 by SIFE on August 13, 2011 - 9:16 pm
Quote
What if I want to resize a small image to a big one?
#4 by Sam on January 18, 2012 - 6:08 am
Quote
Ok so it’s basically just a way of flattening out images. The only problem is the third image looks like it’s a little squished. I guess that can’t be helped though.
#5 by Jane Davidson on February 18, 2012 - 1:49 pm
Quote
Usefull article. Simple code and the final result is wirth it.
#6 by College Universities - Editor on April 1, 2012 - 10:27 pm
Quote
On the third image is it just they way I’m looking at it or I agree with Sam, I think it looks smashed down a little. Thanks for posting this, keep the tips coming.
#7 by kristal jane on June 2, 2012 - 8:51 am
Quote
Wow nice blog. it is useful article the final issue is worthy. thanks for posting keep it good and more power.
#8 by Steve on June 22, 2012 - 2:33 pm
Quote
Hi
Not sure if you still monitor this but I’m having a job and a half with liquid rescale. I cannot for the life of me get it working. Error message is:
PHP Fatal error: Uncaught exception ‘ImagickException’ with message ‘delegate library support not built-in `/Users/mainuser/Sites/development/php/imagick/seam-carving/test.jpg’ (LQR) @ error/resize.c/LiquidRescaleImage/1974
Can you or any readers shed any light on it?
Cheers