# iterate through all the files in the current directory # identify the type of image file (regardless of extension) import os import imghdr # list files in the current working directory for f in os.listdir('.'): if os.path.isfile(f): imgtype = imghdr.what(f) if imgtype is None: imgtype = "not image" print "'" + f + "'" + " is type " + imgtype #output: (for me) #'2007 Oct 31 146.jpg' is type jpeg # #'2007 Oct 31 147.jpg' is type jpeg # #'2007 Oct 31 148.jpg' is type jpeg # #'2007 Oct 31 149.image' is type jpeg # #'2007 Oct 31 150.jpg' is type jpeg # #'big kitty.GI' is type gif # #'eric.image' is type jpeg # #'LICENSE.txt' is type not image # #'NEWS.txt' is type not image #
A python example based blog that shows how to accomplish python goals and how to correct python errors.
Showing posts with label jpeg. Show all posts
Showing posts with label jpeg. Show all posts
Wednesday, September 16, 2009
Python - determine an image's type (regardless of extension)
Subscribe to:
Posts (Atom)