views:

46

answers:

1

Hi.

I would like to resize (downscale) some images the way that Facebook does it. ImageMagick, but hey, I'm open for suggestions :)

I believe Facebook is doing this:

Say you have a max width x height of 250x200, Facebook is optimizing the use of this. Tries to use as much of the 250x200 as possible. If for instance you scale down an image and get 220x200, then they cut from the top and the bottom of the image until they use as much as possible of the 250x200 frame. Actually I think they take more from the bottom, than the top (around 1:2.5), which I believe is because most pictures have the head at the top and Facebook realizes this.

Is there any name for this kind of resizing algorithm? And is there any way to have ImageMagick do this?

Thanks in advance!

Edit It actually appears that Facebook might not be doing this "smart" resizing technique after all. They just resize where they have a minwidth/minheight. Then when they show the image in their album, they cut from the top/bottom or left/right to use as much as possible for the frame (that is how I perceive it at least).

-Tobias

+1  A: 

You can use ImageMagick to get the dimensions of an image, scale then crop it. As to whether you are accurately describing the algorithm Facebook uses, I don't know.

I think the following link addresses the problem you're trying to tackle:

http://www.imagemagick.org/Usage/resize/#space_fill

The example they give at the very end is...

convert logo: \
      -resize 160x -resize 'x160<'   -resize 50% \
      -gravity center  -crop 80x80+0+0 +repage   space_fill_2.jpg

That command resizes an image to be 160 pixels wide, resizes it to be 160 pixels tall, takes the larger of the two resized images and shrinks it by half, and crop it to 80x80.

The following may be of interest to you:

http://www.google.com/search?q=image+entroy+cropping

I've read several documents about using image entropy to choose what part of the image to crop.

Another related link -

http://stackoverflow.com/questions/1516736/django-sorl-thumbnail-crop-picture-head

edits: added related links, specified an example command for doing a similar task with link to source of example.

EMPraptor
I was mostly looking for a single command to do it, so I could do it on-the-fly using streams only. To make ImageMagick resize, but fill out as much as possible of the bounding box I give it.
freeall
I don't know of such a command, and I don't know why they would include such a command. ImageMagick is supposed do generic image processing. Its purpose isn't to implement every image manipulation possible. Maybe you could use the ImageMagic library or some other image manipulation library to make a tool for doing this specific thing.
EMPraptor