Pillow: redimensionando imagens com Python

This commit is contained in:
Luiz Otávio
2023-02-19 10:21:05 -03:00
parent 10a128dcc7
commit dde5edcf48
3 changed files with 26 additions and 0 deletions

BIN
aula200/ new.JPG Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

26
aula200/main.py Normal file
View File

@@ -0,0 +1,26 @@
# Pillow: redimensionando imagens com Python
# Essa biblioteca é o Photoshop do Python 😂
from pathlib import Path
from PIL import Image
ROOT_FOLDER = Path(__file__).parent
ORIGINAL = ROOT_FOLDER / 'original.JPG'
NEW_IMAGE = ROOT_FOLDER / ' new.JPG'
pil_image = Image.open(ORIGINAL)
width, height = pil_image.size
exif = pil_image.info['exif']
# width new_width
# height ??
new_width = 640
new_height = round(height * new_width / width)
new_image = pil_image.resize(size=(new_width, new_height))
new_image.save(
NEW_IMAGE,
optimize=True,
quality=70,
# exif=exif,
)

BIN
aula200/original.JPG Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 342 KiB