Created
September 15, 2023 14:44
-
-
Save bgyarfas/70f25a29adc79ed5359f12d149a20968 to your computer and use it in GitHub Desktop.
Fix DJI JPEGs for instant-ngp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import itertools | |
from pathlib import Path | |
from PIL import Image | |
def fix_dji_jpegs(path): | |
""" Load and re-save with Pillow. | |
This removes the JPEG Marker 0 that STB doesn't like. """ | |
# Directory containing the JPEG images | |
p = Path(path) | |
try: | |
for filename in itertools.chain(p.glob("*.JPG"), p.glob("*.jpg"), p.glob("*.JPEG"), p.glob("*.jpeg")): | |
with Image.open(filename) as img: | |
# You can perform any image processing operations here if needed. | |
# For example, resizing: | |
# img = img.resize((new_width, new_height)) | |
# Save the image as JPEG, overwriting the original file | |
img.save(filename, "JPEG") | |
print(f"Processed and overwritten: {filename}") | |
except FileNotFoundError: | |
print(f"Input directory '{path}' not found.") | |
except Exception as e: | |
print(f"An error occurred: {e}") | |
if __name__ == "__main__": | |
if len(sys.argv) < 2: | |
print("Usage: python fix_dji_jpegs.py <path>") | |
sys.exit(1) | |
fix_dji_jpegs(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment