파이썬에서 여러 장의 그림 파일등을 리스트 형태로 이어 붙여서 GIF 파일로 저장할 수 있다. 대표적인 방법은 두 가지가 있다. 두 가지 방법 모두 파이썬 이미지 라이브러리인 Pillow로 이미지를 불러왔다고 가정한다.
1. 리스트에서 곧바로 저장하기
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 이미지 파일을 열어서 리스트에 저장 | |
images = [Image.open(image) for image in image_paths] | |
# 첫 번째 이미지를 기준으로 GIF 파일 생성 (duration은 밀리초 단위) | |
images[0].save(gif_path, save_all=True, append_images=images[1:], duration=duration, loop=0) |
2. imageio를 이용한 방법 (패키지는 pip install imageio로 설치가 선행되어야 함)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 이미지 파일을 열어서 리스트에 저장 | |
images = [Image.open(image) for image in image_paths] | |
# 이미지 간격 duration은 초 단위 | |
imageio.mimsave(gif_path, images, duration=duration) |
'노트정리 > 파이썬 Python' 카테고리의 다른 글
파이썬 (python) 프로젝트 사용 패키지 버전 추출 (requirments.txt 만들기) (1) | 2024.09.17 |
---|---|
아나콘다(anaconda)의 환경 활성화와 비활성화 할 때, 특정 명령어 실행하기 (1) | 2024.04.05 |
아나콘다(anaconda, miniconda)에서 가상환경 마다 환경변수 PATH 설정하기(리눅스) (0) | 2024.04.01 |
vscode에서 파이썬 독스트링(docstring) 보는 단축키 설정 방법 (0) | 2023.12.04 |
제프리 에이븐 저/송주경 역 (2019), 파이썬을 활용한 스파크 프로그래밍, 에이콘출판사. (0) | 2023.09.19 |
주피터랩에서 파이썬 텔레그램 봇(telegram bot)을 이용해 메시지 보내기 (0) | 2023.08.08 |
주피터랩(jupyter lab)에 토큰이나 패스워드 없이 들어가기 (0) | 2023.06.12 |
파이썬에서 epub 읽어오는 방법과 영어사전 사용법 (0) | 2022.04.13 |