본문 바로가기

Python

무료 HEIC to JPG, HEIC to BMP , HEIC to PNG 변환기

반응형

https://youtu.be/OQxf3Ud9XWQ

 

- YouTube

 

www.youtube.com

 

아이폰 사용자가 많아 지면서 사진 저장시 HEIC 확장자로 저장되는 경우가 많은데, 많은 PC프로그램에서 HEIC를 지원하지 않다 보니, JPG, BMP, PNG등으로 변환하기를 원하는 경우가 많습니다.

그래서 만들었습니다. HEIC to JPG 변환기입니다. 물론 BMP, PNG로도 가능합니다.

필요한 모듈은 pillow와 pyheif 또는 pillow_heif 입니다.

pyheif의 경우, Microsoft의 Visual C++ Build Tools도 설치해야 하고 libheif도 설치해야 하는등 사전 작업이 많고, 그럼에도 불구하고 제대로 설치 안 되는 경우가 있어서 저희는 pillow_heif를 사용하도록 하겠습니다.

참고로 libheif설치 과정은 다음과 같습니다.

git clone https://github.com/microsoft/vcpkg.git
cd vcpkg
.\bootstrap-vcpkg.bat
.\vcpkg.exe install libheif

 

Microsoft의 Visual C++ Build Tools 설치는 아래 링크에서 하면 됩니다.

https://visualstudio.microsoft.com/visual-cpp-build-tools/

 

Microsoft C++ Build Tools - Visual Studio

The Microsoft C++ Build Tools provides MSVC toolsets via a scriptable, standalone installer without Visual Studio. Recommended if you build C++ libraries and applications targeting Windows from the command-line (e.g. as part of your continuous integration

visualstudio.microsoft.com

저희는 아래처럼 2개 모듈만 설치하고 진행하겠습니다.

pip install pillow-heif

 

아래는 최종 PYTHON CODE입니다.

 

import os
from tkinter import Tk, Label, Entry, Button, filedialog, messagebox, StringVar, OptionMenu
from tkinter import ttk
from PIL import Image
import pillow_heif

def heic_to_format(heic_path, output_path, output_format):
    heif_file = pillow_heif.open_heif(heic_path)
    image = Image.frombytes(
        heif_file.mode,
        heif_file.size,
        heif_file.data,
        "raw",
        heif_file.mode,
        heif_file.stride,
    )
    # 'JPG' 대신 'JPEG'를 사용
    if output_format.lower() == 'jpg':
        output_format = 'jpeg'
    image.save(output_path, output_format.upper())

def select_folder():
    folder_path = filedialog.askdirectory()
    if folder_path:
        folder_entry.delete(0, 'end')
        folder_entry.insert(0, folder_path)

def convert_images():
    folder_path = folder_entry.get()
    output_format = format_var.get()
   
    if not folder_path:
        messagebox.showerror("오류", "폴더 경로를 입력하거나 선택하세요.")
        return

    if not os.path.isdir(folder_path):
        messagebox.showerror("오류", "유효한 폴더 경로를 입력하세요.")
        return

    if output_format not in ['jpg', 'jpeg', 'bmp', 'png']:
        messagebox.showerror("오류", "유효한 출력 형식을 선택하세요.")
        return

    heic_files = [f for f in os.listdir(folder_path) if f.lower().endswith(".heic")]
    total_files = len(heic_files)
   
    if total_files == 0:
        messagebox.showinfo("정보", "변환할 HEIC 파일이 없습니다.")
        return

    progress_bar["maximum"] = total_files

    for i, filename in enumerate(heic_files):
        heic_path = os.path.join(folder_path, filename)
        output_path = os.path.join(folder_path, f"{os.path.splitext(filename)[0]}.{output_format}")
        heic_to_format(heic_path, output_path, output_format)
        progress_bar["value"] = i + 1
        root.update_idletasks()
        print(f"변환 완료: {heic_path} -> {output_path}")

    messagebox.showinfo("완료", f"모든 HEIC 파일이 {output_format.upper()}로 변환되었습니다.")

# Tkinter GUI 구성
root = Tk()
root.title("HEIC to Format 변환기")

Label(root, text="폴더 경로:").grid(row=0, column=0, padx=10, pady=10)
folder_entry = Entry(root, width=50)
folder_entry.grid(row=0, column=1, padx=10, pady=10)

select_button = Button(root, text="폴더 선택", command=select_folder)
select_button.grid(row=0, column=2, padx=10, pady=10)

Label(root, text="출력 형식:").grid(row=1, column=0, padx=10, pady=10)
format_var = StringVar(root)
format_var.set("jpg")  # 기본값 설정
format_menu = OptionMenu(root, format_var, "jpg", "jpeg", "bmp", "png")
format_menu.grid(row=1, column=1, padx=10, pady=10)

convert_button = Button(root, text="변환 시작", command=convert_images)
convert_button.grid(row=2, column=1, padx=10, pady=10)

progress_bar = ttk.Progressbar(root, orient="horizontal", length=400, mode="determinate")
progress_bar.grid(row=3, column=0, columnspan=3, padx=10, pady=10)

root.mainloop()

 

실행 파일 만드는 방법은 아시겠지만, 아래처럼 진행하면 됩니다.

pyinstaller -w -F --icon 내아이콘.ico heic2jpg_v0.8.py

 

소스 파일입니다.

heic2jpg_v0.8.py
0.00MB

 

실행파일은 아래 링크에서 받으세요. 

https://mega.nz/file/PA9GgTDT#TX1feG3zqLXHD1rbrw31t88t57BlNOnyyXHWiUjEo40

 

반응형