Pillow: redimensionando imagens com Python
This commit is contained in:
BIN
aula200/ new.JPG
Normal file
BIN
aula200/ new.JPG
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 23 KiB |
26
aula200/main.py
Normal file
26
aula200/main.py
Normal 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
BIN
aula200/original.JPG
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 342 KiB |
Reference in New Issue
Block a user