Advertisement
phillips321

synothumb.py phillips321.co.uk

Aug 27th, 2013
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.95 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # sudo mount_nfs -P 192.168.0.2:/volume1/photo /Users/phillips321/nfsmount
  3. import os,sys,Image
  4. try:
  5.     rootdir=sys.argv[1]
  6. except:
  7.     print "Usage: %s directory" % sys.argv[0]
  8.     sys.exit(0)
  9. imageList=[]
  10.  
  11. # Finds all images of type jpg,png,jpeg,tif,bmp
  12. for path, subFolders, files in os.walk(rootdir):
  13.     for file in files:
  14.         if os.path.splitext(file)[1].lower() == ".jpg" or ".png" or ".jpeg" or ".tif" or ".bmp":
  15.             if "@eaDir" not in path:
  16.                 if file != ".DS_Store": imageList.append(os.path.join(path,file))
  17.  
  18. xlName="SYNOPHOTO:THUMB_XL.jpg" ; xlSize=(1280,1280) #XtraLarge
  19. lName="SYNOPHOTO:THUMB_L.jpg" ; lSize=(800,800) #Large
  20. bName="SYNOPHOTO:THUMB_B.jpg" ; bSize=(640,640) #Big
  21. mName="SYNOPHOTO:THUMB_M.jpg" ; mSize=(320,320) #Medium
  22. sName="SYNOPHOTO:THUMB_S.jpg" ; sSize=(160,160) #Small
  23.  
  24. for imagePath in imageList:
  25.     imageDir,imageName = os.path.split(imagePath)
  26.     thumbDir=os.path.join(imageDir,"@eaDir",imageName)
  27.     if os.path.isdir(thumbDir) != 1:
  28.         try:os.makedirs(thumbDir)
  29.         except:continue
  30.     image=Image.open(imagePath)
  31.     if os.path.isfile(os.path.join(thumbDir,xlName)) != 1:
  32.         print "Now working on %s : %s" % (imageName,xlName)
  33.         image.thumbnail(xlSize, Image.ANTIALIAS)
  34.         image.save(os.path.join(thumbDir,xlName))
  35.         print "Now working on %s : %s" % (imageName,lName)
  36.         image.thumbnail(lSize, Image.ANTIALIAS)
  37.         image.save(os.path.join(thumbDir,lName))
  38.         print "Now working on %s : %s" % (imageName,bName)
  39.         image.thumbnail(bSize, Image.ANTIALIAS)
  40.         image.save(os.path.join(thumbDir,bName))
  41.         print "Now working on %s : %s" % (imageName,mName)
  42.         image.thumbnail(mSize, Image.ANTIALIAS)
  43.         image.save(os.path.join(thumbDir,mName))
  44.         print "Now working on %s : %s" % (imageName,sName)
  45.         image.thumbnail(sSize, Image.ANTIALIAS)
  46.         image.save(os.path.join(thumbDir,sName))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement