본문 바로가기
programming/python-sample

[macOS] HEIC 파일 포맷 변환 (magic 사용)

by sniffer-k 2023. 6. 19.

macOS에서 *.HEIC 확장자를 가지는 사진 파일을 자동으로 JPG로 변환해주는 스크립트는 다음과 같다.

 

사전 설치 프로그램 (magick)

brew install imagemagick

 

전체 변환 스크립트

 

import os, subprocess

read_target_dir = './target_folder'

save_target_dir = './target_folder'	# 변환된 파일을 저장할 경로

for file_name in os.listdir(read_target_dir):

	if file_name.lower().endswith(".heic"):
		name,ext = os.path.splitext(file_name)

		print('target : ' + os.path.join(read_target_dir, file_name))

		subprocess.run(["magick", os.path.join(read_target_dir, file_name), os.path.join(save_target_dir, name + '.jpg')])

print('All done')

 

read_target_dir 경로와 save_target_dir 이 같으면 다음 그림과 같이 같은 폴더에 변환된 사진 파일이 저장된다

 

파일 변환 결과

*.HEIC 파일 포맷을 변경하는 방법은 ... 내가 찾아보기로는  magick, heic-to-jpg 가 있다.

다음 포스트에서는 heic-to-jpg 에 대해 소개해야겠다 ..

 

 


https://pypi.org/project/heic-to-jpg/

 

heic-to-jpg

Convert .heic images to .jpg

pypi.org

 

 

728x90