• 카테고리

    질문 & 답변
  • 세부 분야

    프로그래밍 언어

  • 해결 여부

    미해결

이미지 에러 발생

24.01.28 11:31 작성 조회수 66

0

  1. ValueError : images do not match 에러가 발생할 수 있습니다.

  2. 이미지가 겹쳐서 뜨는 현상이 발생할 수 있습니다.

따라서 해당 에러를 해결하기 위한 코드 GPT를 이용하여 재작성한 결과는 아래와 같습니다.

저의 환경은 다음과 같습니다.
- python version : 3.11.5
- packages version
- pillow : 10.2.0
- image : 1.5.33

# 폴더 내 다양한 파일들은 한번에 가져와서 리스트 형태로 반환해주는 패키지
import glob
# 파이썬 이미지 처리 라이브러리
from PIL import Image

path_in = './project/images/*.png'
path_out = './project/image_out/result.gif'

# Load all images
images = [Image.open(f) for f in sorted(glob.glob(path_in))]

# Get the size of the first image
width, height = images[0].size

# Resize all images to match the size of the first image
images = [img.resize((width, height), Image.Resampling.LANCZOS).convert("P") for img in images]

# Save GIF
images[0].save(
    fp=path_out,
    format='GIF',
    append_images=images[1:],
    save_all=True,
    duration=300,
    loop=0
)

답변 1

답변을 작성해보세요.

0

안녕하세요.

현재 예제 소스코드는 잘 실행되는데

GPT를 활용해서 다시 생성하신건가요?

이미지는 원래 겹쳐서 실행이 되는 부분이고 제가 생각에는 Pillow 버전을 조금 낮춰서 실행 해보시는것도

좋을 것 같습니다.