Skip to content

Instantly share code, notes, and snippets.

@bno1
Last active March 5, 2024 07:34
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bno1/2f3ec41431f3c373edd24ddf82eda875 to your computer and use it in GitHub Desktop.
Save bno1/2f3ec41431f3c373edd24ddf82eda875 to your computer and use it in GitHub Desktop.
A Gimp script for a friend to help them convert their photo collection from HEIC to JPEG. To run open up Gimp, go to Filters -> Python-Fu -> Console and paste the script below. Make sure to edit the last line with your photo directory. For the JPEG output it uses 95% quality and the rest of the settings are maxed out (floating-point dct and 4:4:…
import gimpfu
import os
import re
import traceback
heic_ext_re = re.compile(r'\.heic$', re.IGNORECASE)
def convert(filename):
new_name = heic_ext_re.sub('.jpg', filename)
if os.path.isfile(new_name):
print('skipping ' + filename)
return
else:
print('converting ' + filename)
quality = 0.95 # 95%. Set to 1.0 for 100% quality.
smoothing = 0.0
optimize = 1
progressive = 1
comment = None
subsmp = 2 # 4:4:4
baseline = 0
restart = 0
dct = 2 # floating-point
image = pdb.gimp_file_load(filename, filename)
layer = pdb.gimp_image_get_active_layer(image)
pdb.file_jpeg_save(image, layer, new_name, new_name, quality, smoothing,
optimize, progressive, comment, subsmp, baseline, restart,
dct)
def convert_heic_in_dir(root):
root = os.path.normpath(root)
for file in os.listdir(root):
if heic_ext_re.search(file):
filename = os.path.join(root, file)
try:
convert(filename)
except Exception as exc:
print('Error converting %s:' % filename)
traceback.print_exc()
# Put your photos directory here
convert_heic_in_dir(r'C:\Users\bno1\Desktop')
@itcy10
Copy link

itcy10 commented Jan 17, 2024

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment