Improved resizing and cropping logic for thumb generation