Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import os
- def get_imlist('/home/rfmonk/Pictures'): # <--- path
- """ Returns a list of filenames for all jpg images in a directory. """
- return [os.path.join(path,f) for f in os.listdir(path) if f.endswith('.jpg')]
- ## credit to computer vision -- oreilly
- """ PIL The Python Imaging Library
- PIL provides general image handling and lots of useful basic image operations like resizing, cropping, rotating, color conversion.
- In [1]: from PIL import Image
- In [2]: import os
- In [3]: for infile in filelist:
- ...: outfile = os.path.splitext(infile)[0] + ".jpg"
- ...: if infile != outfile:
- ...: try:
- ...: Image.open(infile).save(outfile)
- ...: except IOError:
- ...: print "cannot convert", infile
- The PIL function open() creates a PIL image object and the save() method saves the image to a file with the given filename.
- """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement