From http://www.white-hat-web-design.co.uk/blog/resizing-images-with-php/