Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: UTF-8 -*-
- #
- # (c) Roberto Gambuzzi
- # Creato: 04/12/2013 12:44:48
- # Ultima Modifica: 04/12/2013 12:45:02
- #
- # v 0.0.1.0
- #
- # file: media_catalog_resizer.py
- # auth: Roberto Gambuzzi <gbinside@gmail.com>
- # desc: NON MI ASSUMO RESPONSABILITA' DI ALCUN GENERE PER L'USO DI QUESTO CODICE
- #
- # $Id: media_catalog_resizer.py 04/12/2013 12:45:02 Roberto $
- # --------------
- import Image
- import os
- import sys
- DIMENSIONE_MASSIMA = (960,720)
- QUALITA = 85
- CARTELLA = r'media/catalog/product'
- UN_MEGA = 1024**3
- def troppogrossa(img, f):
- return img.size[0]>1024 or img.size[1]>1024 or os.path.getsize(f)>UN_MEGA
- if __name__=="__main__":
- for root, dirs, files in os.walk(CARTELLA):
- print root
- if 'cache' in root or 'watermark' in root:
- continue
- for f in files:
- full_file_name = os.path.join(root,f)
- try:
- img = Image.open(full_file_name)
- except:
- continue
- print f
- nomefile = os.path.basename(f)
- if troppogrossa(img, full_file_name):
- img.thumbnail(DIMENSIONE_MASSIMA, Image.ANTIALIAS)
- img.save(full_file_name, quality=QUALITA)
- print '*'*79
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement