Crop image to visible area

view story

http://stackoverflow.com – I want to crop image to store only real image, I don't want to have small image on big area of null or white background like this image below. Is there way to do it without looking on every pixel in some loops? need to use some server side software, could be php(in witch all project is), java or some linux console programs. (HowTos)