Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing recursively a folder and move HEIC to JPG #3

Open
ratounade opened this issue Jan 20, 2024 · 0 comments
Open

Parsing recursively a folder and move HEIC to JPG #3

ratounade opened this issue Jan 20, 2024 · 0 comments

Comments

@ratounade
Copy link

Hi,
Find below adjusted code if you want to parse recursively a folder. The initial HEIC will be renamed in *.heic.old
You than can easily revert to initial status by removing *.heic.jpg and rename *.heic.old in *.heic
enjoy

#HEIC to JPG image format batch conversion script for Python 3. Tested on Windows 10.
#You will need to have ImageMagick installed: https://www.imagemagick.org/

import os, subprocess

#Convert recursively (parsing all sub directorites) all HEIC files into JPG from the rootdir below
#then script would rename initial files to *.heic.old
rootdir = "\\xxx.xxx.x.xx\Public\Shared Pictures\Photo"

def heicToJpg(rootdir):
for it in os.scandir(rootdir):
if it.is_dir():
print('parsing %s...' % it.path)
for filename in os.listdir(it.path):
if filename.lower().endswith(".heic"):
print('Converting to jpg %s...' % os.path.join(it, filename))
subprocess.run(["magick", "%s" % os.path.join(it, filename), "%s" % os.path.join(it, (filename[0:-5] + '.heic.jpg'))])
# os.remove("%s" % os.path.join(it, filename))
os.rename(os.path.join(it, filename), os.path.join(it, filename[0:-5] + '.heic.old'))
heicToJpg(it)
else: #we are on a file
filename = it.path
if filename.lower().endswith(".heic"):
print('Converting to JPG %s...' % os.path.join(it, filename))
subprocess.run(["magick", "%s" % os.path.join(it, filename), "%s" % os.path.join(it, (filename[0:-5] + '.heic.jpg'))])
# os.remove("%s" % os.path.join(it, filename))
os.rename(os.path.join(it, filename), os.path.join(it, filename[0:-5] + '.heic.old'))
heicToJpg(rootdir)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant