Create photo frame


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  1. # -*- coding: utf-8 -*-
  2. """
  3. Inserisce una cornice bianca nella foto selezionata
  4. """
  5.  
  6.  
  7. import os,sys
  8. from PIL import Image,ImageOps
  9.  
  10. WHITE_BORDER = 2
  11. BLACK_BORDER = 20
  12.  
  13. def main(argv):
  14.  
  15. if not os.path.exists(argv[1]):
  16. print "file non trovato"
  17. return
  18.  
  19. img = Image.open(os.path.abspath(argv[1])) # In Argv[1] sorgente
  20. img = ImageOps.expand(img,border = BLACK_BORDER, fill = 'black')
  21. img = ImageOps.expand(img,border = WHITE_BORDER, fill = 'white')
  22. img = ImageOps.expand(img,border = BLACK_BORDER, fill = 'black')
  23.  
  24. img.save(argv[2],"JPEG") #In argv[2] il percorso + file di destinazione
  25.  
  26.  
  27. if __name__ == "__main__":
  28.  
  29. if len(sys.argv) > 1:
  30. main(sys.argv)

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.