Skip to content

Instantly share code, notes, and snippets.

@seveibar
Last active September 30, 2015 16:08
Show Gist options
  • Save seveibar/30122250485cdd02cf84 to your computer and use it in GitHub Desktop.
Save seveibar/30122250485cdd02cf84 to your computer and use it in GitHub Desktop.
# This script is for automatically labeling all the images in a directory with their
# names (for lab reports, technical documents etc.). Uses ImageMagick's convert command.
# Currently windows specific, but it should be easy to make compatible with linux
# This may also be possible as a one-liner with image magick.
import os
import os.path
try: os.system('rmdir labeled /s /q')
except: pass
os.system("mkdir labeled")
print "Scanning for files"
files = [f for f in os.listdir('.') if os.path.isfile(f) and f.split('.')[-1].lower() == 'png']
print "Found",files
print "-" * 40
for f in files:
print f
cmd = "convert \"" + f + "\" -background white label:\"" + ".".join(f.split(".")[:-1]) + "\" -gravity Center -append \"labeled\\" + f + "\""
print cmd
os.system(cmd)
print "-"*30
print "Done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment