Advertisement
gambuzzi

Untitled

Dec 4th, 2013
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.27 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: UTF-8 -*-
  3. #
  4. # (c) Roberto Gambuzzi
  5. # Creato:          04/12/2013 12:44:48
  6. # Ultima Modifica: 04/12/2013 12:45:02
  7. #
  8. # v 0.0.1.0
  9. #
  10. # file: media_catalog_resizer.py
  11. # auth: Roberto Gambuzzi <gbinside@gmail.com>
  12. # desc: NON MI ASSUMO RESPONSABILITA' DI ALCUN GENERE PER L'USO DI QUESTO CODICE
  13. #
  14. # $Id: media_catalog_resizer.py 04/12/2013 12:45:02 Roberto $
  15. # --------------
  16.  
  17. import Image
  18. import os
  19. import sys
  20.  
  21. DIMENSIONE_MASSIMA = (960,720)
  22. QUALITA = 85
  23. CARTELLA = r'media/catalog/product'
  24. UN_MEGA = 1024**3
  25.  
  26. def troppogrossa(img, f):
  27.     return img.size[0]>1024 or img.size[1]>1024 or os.path.getsize(f)>UN_MEGA
  28.  
  29. if __name__=="__main__":
  30.     for root, dirs, files in os.walk(CARTELLA):
  31.         print root
  32.         if 'cache' in root or 'watermark' in root:
  33.             continue
  34.         for f in files:
  35.             full_file_name = os.path.join(root,f)
  36.             try:
  37.                 img = Image.open(full_file_name)
  38.             except:
  39.                 continue
  40.             print f
  41.             nomefile = os.path.basename(f)
  42.  
  43.             if troppogrossa(img, full_file_name):
  44.                 img.thumbnail(DIMENSIONE_MASSIMA, Image.ANTIALIAS)
  45.                 img.save(full_file_name, quality=QUALITA)
  46.         print '*'*79
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement