- # crop top square.
- if img.size[1] > img.size[0]:
- img = img.crop((0, 0, img.size[0], img.size[0]))
- else:
- left = round((img.size[0] - img.size[1])/2)
- img = img.crop((
- left,
- 0,
- left + img.size[1],
- img.size[1]
- ))
+ if self.crop_to_square:
+ # crop top square.
+ if img.size[1] > img.size[0]:
+ img = img.crop((0, 0, img.size[0], img.size[0]))
+ else:
+ left = round((img.size[0] - img.size[1])/2)
+ img = img.crop((
+ left,
+ 0,
+ left + img.size[1],
+ img.size[1]
+ ))