All pastes #769462 Raw Edit

Mine

public text v1 · immutable
·published 2007-11-11 13:23 UTC
rendered paste body
#!/usr/bin/python
import os
import hashlib
import sys
import shutil

paths=[]
imagepath=sys.argv[1]+'/images/'

print 'Creating Image-List...'
for root,dirs,files in os.walk(sys.argv[1]):
	for file in files:
		paths+=[root+'/'+file]
print 'Moving Images to image-folder...'
os.mkdir(imagepath)
for i in paths:
		extension=os.path.splitext(i)[1].lower()
		if extension in ('.jpg','.gif','.png'):
			shutil.move(i,imagepath)

print 'Renaming Images to their MD5-Hash...'

for file in os.listdir(imagepath):
		extension=os.path.splitext(file)[1].lower()
		m=hashlib.md5()
		picfile=open(imagepath+file,'r')
		m.update(picfile.read())
		picfile.close()
		currenthash=m.hexdigest()
		os.rename(imagepath+file,imagepath+currenthash+extension)

print 'Creating thumbnails...'
os.mkdir(sys.argv[1]+'/thumbs')
os.system('mogrify -path '+sys.argv[1]+'/thumbs -thumbnail 250x250 '+imagepath+'*')
#print hashes