画像の横幅と縦幅を取得 width height


print ('画像の横幅と縦幅を取得 width height')

from PIL import Image

img = Image.open('test_data/imori.jpg')

width = img.width
height = img.height
print('width=' + str(width))
print('height=' + str(height))

print('Success')
	
出力
画像の横幅と縦幅を取得 width height
width=640
height=359
Success

	

画像のリサイズ(縮小、拡大) | resize


print ('画像のリサイズ(縮小、拡大)')

from PIL import Image

img = Image.open('test_data/imori.jpg')

#img_resize = img.resize((64, 64))
img_resize = img.resize((128, 128), Image.LANCZOS) #高品質だが時間がかかる
img_resize.save('output.jpg')

print('Success')