このオリジナル画像を縮小、拡大、回転、切り抜き、左右反転、上下反転、透過するプログラムです。

from PIL import Image, ImageOps
img = Image.open('original.png')
#サイズを取得
height, width = img.size
print(height, width)
#縮小
fact = 0.5
result_height = int(height * fact)
result_width = int(width * fact)
img.resize((result_height, result_width)).save('result1.png')
#拡大
fact = 1.5
result_height = int(height * fact)
result_width = int(width * fact)
img.resize((result_height, result_width), resample=Image.HAMMING).save('result2.png')
#回転
teta = 45
img.rotate(teta).save('result3.png')
#切り抜き
left = 220
upper = 100
right = 320
lower = 200
img.crop((left, upper, right, lower)).save('result4.png')
#左右反転
ImageOps.mirror(img).save('result5.png')
#上下反転
ImageOps.flip(img).save('result6.png')
#半透明化
fact = 0.5
val = int(255*fact)
img_copy = img.copy()
img_copy.putalpha(val)
img_copy.save('result7.png')




(切り抜き)


