카테고리 없음
webp 파일을 jpg 파일로 변환하는 파이썬 코드
A1A2
2023. 3. 1. 14:59
반응형
webp 파일을 jpg 파일로 변환하는 파이썬 코드
from PIL import Image
import os
# 원본 이미지가 저장된 폴더 경로
input_dir = './input/'
# 변환된 이미지를 저장할 폴더 경로
output_dir = './output/'
# output_dir 폴더가 없으면 생성
if not os.path.exists(output_dir):
os.makedirs(output_dir)
# input_dir 폴더에 있는 모든 파일 이름을 가져옴
files = os.listdir(input_dir)
# input_dir 폴더에 있는 이미지 파일들만 추출
image_files = [f for f in files if f.endswith('.webp')]
# 각 이미지 파일을 변환하여 output_dir 폴더에 저장
for filename in image_files:
# 이미지 파일 로드
input_path = os.path.join(input_dir, filename)
img = Image.open(input_path)
# 이미지 파일 변환
img = img.convert('RGB')
output_path = os.path.join(output_dir, os.path.splitext(filename)[0] + '.jpg')
img.save(output_path)
print(f'"{filename}" converted to "{os.path.basename(output_path)}"')
실행파일 만들기(windows)
1.pyinstaller 설치
pip install pyinstaller
2.exe 파일로 빌드
pyinstaller --onefile webp2jpg.py
실행파일 만들기(Mac OS)
1.py2app 설치
맥에서는 pyinstaller 대신에 py2app을 사용해서 실행 파일을 만들 수 있습니다. py2app을 사용하기 위해서는 맥에서 설치가 되어 있어야 합니다. py2app 설치는 아래 명령어를 이용하여 설치할 수 있습니다.
pip install py2app
2.exe 파일로 빌드
설치가 끝나면, 아래와 같이 터미널에서 명령어를 실행하여 실행 파일을 만들 수 있습니다.
python3 setup.py py2app
반응형