79 lines
2.4 KiB
Python
79 lines
2.4 KiB
Python
import os
|
|
from tkinter import Tk, filedialog, Button, Label, ttk
|
|
from PIL import Image
|
|
import pillow_heif
|
|
|
|
# Register HEIF support
|
|
pillow_heif.register_heif_opener()
|
|
|
|
def convert_heif_to_jpg_gui(input_folder, output_folder):
|
|
os.makedirs(output_folder, exist_ok=True)
|
|
|
|
files = [f for f in os.listdir(input_folder) if f.lower().endswith(('.heic', '.heif'))]
|
|
total = len(files)
|
|
|
|
if total == 0:
|
|
status_label.config(text="⚠️ No HEIF/HEIC files found.")
|
|
return
|
|
|
|
progress_bar["maximum"] = total
|
|
|
|
for i, filename in enumerate(files, 1):
|
|
input_path = os.path.join(input_folder, filename)
|
|
output_path = os.path.join(output_folder, os.path.splitext(filename)[0] + '.jpg')
|
|
|
|
try:
|
|
with Image.open(input_path) as img:
|
|
rgb_img = img.convert("RGB")
|
|
rgb_img.save(output_path, "JPEG")
|
|
status_label.config(text=f"Converting {filename} ({i}/{total})")
|
|
except Exception as e:
|
|
print(f"Failed to convert {filename}: {e}")
|
|
|
|
progress_bar["value"] = i
|
|
app.update_idletasks()
|
|
|
|
status_label.config(text="✅ Conversion complete!")
|
|
|
|
def browse_input():
|
|
folder = filedialog.askdirectory(title="Select Input Folder (HEIF images)")
|
|
if folder:
|
|
input_label.config(text=folder)
|
|
app.input_folder = folder
|
|
|
|
def browse_output():
|
|
folder = filedialog.askdirectory(title="Select Output Folder (JPG images)")
|
|
if folder:
|
|
output_label.config(text=folder)
|
|
app.output_folder = folder
|
|
|
|
def convert():
|
|
if hasattr(app, "input_folder") and hasattr(app, "output_folder"):
|
|
convert_heif_to_jpg_gui(app.input_folder, app.output_folder)
|
|
else:
|
|
status_label.config(text="❗ Please select both folders first.")
|
|
|
|
# GUI Setup
|
|
app = Tk()
|
|
app.title("HEIF to JPG Converter")
|
|
app.geometry("500x250")
|
|
|
|
Button(app, text="Select HEIF Input Folder", command=browse_input).pack(pady=5)
|
|
input_label = Label(app, text="No input folder selected")
|
|
input_label.pack()
|
|
|
|
Button(app, text="Select JPG Output Folder", command=browse_output).pack(pady=5)
|
|
output_label = Label(app, text="No output folder selected")
|
|
output_label.pack()
|
|
|
|
Button(app, text="Convert HEIF to JPG", command=convert).pack(pady=10)
|
|
|
|
# Progress bar
|
|
progress_bar = ttk.Progressbar(app, orient="horizontal", length=400, mode="determinate")
|
|
progress_bar.pack(pady=5)
|
|
|
|
status_label = Label(app, text="")
|
|
status_label.pack()
|
|
|
|
app.mainloop()
|