rotate: fix rotate

Image.rotate had different behavior under 3.1.x, transpose works on all versions
This commit is contained in:
Nick Zatkovich 2017-07-31 02:01:48 -07:00
parent cac04c1271
commit 7251b14892
2 changed files with 14 additions and 3 deletions

View file

@ -134,7 +134,7 @@ wikilrs_horiz.png:
0,0 killers 0,0 killers
wikilrs.png: wikilrs_horiz.png wikilrs.png: wikilrs_horiz.png
python rotate.py wikilrs_horiz.png -90 $@ python rotate.py wikilrs_horiz.png 270 $@
cp $@ ../ cp $@ ../
wivctms.png: wivctms.png:

View file

@ -9,8 +9,19 @@ import os
img = Image.open(sys.argv[1]) img = Image.open(sys.argv[1])
img.load() img.load()
angle = int(sys.argv[2])
if angle % 90 == 0:
if angle == 90 or angle == -270:
method = Image.ROTATE_90
elif abs(angle) == 180:
method = Image.ROTATE_180
else:
method = Image.ROTATE_270
img2 = img.transpose(method)
else:
img2 = img.rotate(int(sys.argv[2]), 0, True) img2 = img.rotate(int(sys.argv[2]), 0, True)
img2.crop() img2 = img2.crop()
if os.path.exists(sys.argv[3]): # delete any previous result file if os.path.exists(sys.argv[3]): # delete any previous result file
os.remove(sys.argv[3]) os.remove(sys.argv[3])
img2.save(sys.argv[3]) img2.save(sys.argv[3])