Skip to content

Instantly share code, notes, and snippets.

@lopezpdvn
Created August 12, 2016 05:22
Show Gist options
  • Save lopezpdvn/37c50a64aec0cbd8b538fc38a786db2a to your computer and use it in GitHub Desktop.
Save lopezpdvn/37c50a64aec0cbd8b538fc38a786db2a to your computer and use it in GitHub Desktop.
ImageMagick scripts
#!/usr/bin/env python3
# coding=utf-8
import sys
from os import walk
from os.path import join
from subprocess import Popen
ROOTFP = sys.argv[1]
PERCENTAGE = sys.argv[2]
CONVERT_CMD = ('mogrify', '-verbose', '-resize', PERCENTAGE+'%')
def get_images(rootfp):
for relpath, dirs, files in walk(rootfp):
for f in files:
yield join(relpath, f)
for i in get_images(sys.argv[1]):
cmd = tuple(CONVERT_CMD + (i,))
with Popen(cmd) as proc:
proc.wait()
@lopezpdvn
Copy link
Author

Test

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