55 lines
1.7 KiB
Python
55 lines
1.7 KiB
Python
|
import Image
|
||
|
import os
|
||
|
|
||
|
def make_miniatures_of_notes(path, div):
|
||
|
subjects = os.listdir(path)
|
||
|
if "bootstrap" in subjects:
|
||
|
subjects.remove("bootstrap")
|
||
|
if "miniatures" in subjects:
|
||
|
subjects.remove("miniatures")
|
||
|
for subject in subjects:
|
||
|
for date in os.listdir(path+"/" + subject):
|
||
|
notes = []
|
||
|
for note in os.listdir(path+"/" + subject +"/" + date ):
|
||
|
notes.append({"tags": "none", "name": note})
|
||
|
image_path = "/" + subject +"/" + date + "/" + note
|
||
|
miniature = make_miniature(path + image_path, div)
|
||
|
if miniature:
|
||
|
print "creating dir " + path + "/mini" + "/" + subject +"/" + date
|
||
|
make_reccurent_dir(path + "/mini" + "/" + subject +"/" + date)
|
||
|
print "saving file " + path + "/mini" + image_path
|
||
|
miniature.save(path + "/mini" + image_path)
|
||
|
|
||
|
def make_reccurent_dir(path):
|
||
|
dirs = path.split("/")
|
||
|
already_made = ""
|
||
|
for directory in dirs:
|
||
|
try:
|
||
|
print "creating: " + already_made + directory
|
||
|
os.mkdir(already_made + directory)
|
||
|
except OSError:
|
||
|
pass
|
||
|
already_made += directory + "/"
|
||
|
|
||
|
def make_miniature(path, div):
|
||
|
print "opening path: " + path
|
||
|
try:
|
||
|
im1 = Image.open(path)
|
||
|
width = im1.size[0] / div
|
||
|
height = im1.size[1] / div
|
||
|
im2 = im1.resize((width, height), Image.ANTIALIAS)
|
||
|
except:
|
||
|
print "couln't open file " + path
|
||
|
return
|
||
|
return im2
|
||
|
|
||
|
def main():
|
||
|
path = raw_input("Path: ")
|
||
|
div = int(raw_input("How many times smaller?: "))
|
||
|
try:
|
||
|
make_miniatures_of_notes(path, div)
|
||
|
except OSError:
|
||
|
pass
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
main()
|