본문 바로가기
Python

[Python] PIL jpg png webp 변환 Image.convert()

by bryan.oh 2021. 3. 25.
반응형

from PIL import Image
Image Conversion
이미지 형식 변환하기

 

Pillow library 를 이용합니다.

# PIL 설치
pip install Pillow

 

JPG -> PNG

from PIL import Image
im = Image.open('hello.jpg').convert('RGB')
im.save('bryan.png', 'png')

 

PNG -> JPG

from PIL import Image
im = Image.open('bryan.png').convert('RGB')
im.save('hello.jpg', 'jpeg')

 

JPG -> WEBP

from PIL import Image
im = Image.open('hello.jpg').convert('RGB')
im.save('tistory.webp', 'webp')

 

WEBP -> JPG

from PIL import Image
im = Image.open('tistory.webp').convert('RGB')
im.save('hello.jpg', 'jpeg')

 

PNG -> WEBP

from PIL import Image
im = Image.open('bryan.png').convert('RGB')
im.save('tistory.webp', 'webp')

 

WEBP -> PNG

from PIL import Image
im = Image.open('tistory.webp').convert('RGB')
im.save('bryan.png', 'png')

 

 

 

728x90
반응형

댓글