Take the 2-minute tour ×

I'm a bit stuck on trying to explain to a customer of my theme that cropping of an image by intelligently figuring out the sweet and right spot is not an easy task at all. I'm even doubtful if that is 100% possible at all.

Say, in a Portrait, if an image is to be cropped as a square or a proportion, will it be possible to focus on the face and do the cropping accordingly.

Here is the question in question, if you wish to know more details http://getsatisfaction.com/autochrome/topics/portrait_image_thumbnail

share|improve this question
Is it not possible for the user to choose where to crop the image? –  Grim... Jan 28 '12 at 20:54
Is there a question here? –  Paolo Jan 28 '12 at 20:54
add comment

4 Answers

It seems to me that the problem your customer is having, is one of aspect ratio.

You very much can determine the source aspect ratio and crop/adjust from there. Just use getImageGeometery().


Or, if using GD:


share|improve this answer
add comment

The "right" place to crop an image is subjective. Determining what is important to the scene composition is as much art as science. If a computer algorithm could figure this out perfectly, you could use it (and a large number of cameras spread across the world) to win the National Geographic photo contest every year :-).

That said, if you can more precisely define the parts of the image which are of interest - such as the faces you mention - then the problem moves from "almost-literally impossible" to "very difficult". You can use a face-detection algorithm and then crop to the smallest bounding box containing all the faces.

share|improve this answer
add comment

Have the user select the portion of the photo they want to crop. Add the offset to GD's cropping params. Good Luck!

share|improve this answer
add comment

A popular solution is to resize and center the image and crop what ever is left over: left and right if the original is too wide, or top and bottom if it's too tall. It's far from perfect for the reasons already mentioned, but easy to automate.

Sample code for doing it with the gd library in this gist: https://gist.github.com/1695782

share|improve this answer
add comment

Your Answer


