Fix a bug in image shrinking code