Add support for different aspect ratios

This patch adds support for different aspect ratios of thumbnail and
full-size image. The script now adapts automatically to the ratio of the
full-size image.