Latest Posts

Fresh thoughts and recent updates from the blog

tistory view

728x90
반응형

 

 

 

파이썬에서 Image 라이브러리 사용 중

 raise OSError(f"cannot write mode {im.mode} as JPEG") from e OSError: cannot write mode RGBA as JPEG

에러났을 때 해결하는 방법

 

 

 

 

 

이 오류는 PIL (Python Imaging Library)에서 JPEG 형식으로 저장할 때

이미지를 RGBA 모드(알파 채널을 포함한 모드)로 저장하려고 시도했기 때문에 발생합니다.

JPEG 형식은 알파 채널을 지원하지 않기 때문에 이 문제를 해결하려면 이미지를 RGB 모드로 변환한 후 저장해야 합니다.

 

 

from PIL import Image

# 이미지를 열고 RGBA 모드인지 확인
my_image = Image.open('path_to_your_image.png')
print(my_image.mode)  # 출력: RGBA

# 이미지를 RGB 모드로 변환
my_image = my_image.convert('RGB')

# 새로운 이름으로 저장
file = 'your_image.jpg'
my_image.save('new_' + file)

 

 

 

 

728x90
반응형
Comments

Visitor Trends

Daily blog stats and creator awards

✿ DASHBOARD
Today

Yesterday

Total

Posts

0

2023 IT Creator
2024 Food Creator
2025 News Creator
2026 News Creator