Advertisement
rfmonk

some notes about python-pil

Jul 28th, 2013
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.92 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import os
  4.  
  5. def get_imlist('/home/rfmonk/Pictures'): # <--- path
  6.     """ Returns a list of filenames for all jpg images in a directory. """
  7.  
  8.     return [os.path.join(path,f) for f in os.listdir(path) if f.endswith('.jpg')]
  9.  
  10. ## credit to computer vision -- oreilly
  11. """ PIL The Python Imaging Library
  12. PIL provides general image handling and lots of useful basic image operations like resizing, cropping, rotating, color conversion.
  13.  
  14. In [1]: from PIL import Image
  15.  
  16. In [2]: import os
  17.  
  18. In [3]: for infile in filelist:
  19.   ...:     outfile = os.path.splitext(infile)[0] + ".jpg"
  20.   ...:     if infile != outfile:
  21.   ...:         try:
  22.   ...:             Image.open(infile).save(outfile)
  23.   ...:         except IOError:
  24.   ...:             print "cannot convert", infile
  25.  
  26.  
  27. The PIL function open() creates a PIL image object and the save() method saves the image to a file with the given filename.
  28. """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement