Last active
September 30, 2015 16:08
-
-
Save seveibar/30122250485cdd02cf84 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# 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