Skip to content

Instantly share code, notes, and snippets.

@felipecustodio
Created August 24, 2021 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felipecustodio/645b60abbd68cf44c0da8f85ef4b0410 to your computer and use it in GitHub Desktop.
Save felipecustodio/645b60abbd68cf44c0da8f85ef4b0410 to your computer and use it in GitHub Desktop.
Reduce filesize of all images in directory
import glob, os
command = """
convert {original_file} \
-sampling-factor 4:2:0 \
-strip \
-quality 85 \
-interlace Plane \
-gaussian-blur 0.05 \
-colorspace RGB \
{new_file}
"""
for file in glob.glob("*.jpeg"):
new_file = "converted/" + file.split(".jpeg")[0] + "_converted.jpeg"
print(file, new_file)
current_command = command.format(original_file=file, new_file=new_file)
stream = os.popen(current_command)
output = stream.read()
print(output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment