home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pypil112.zip / Scripts / pilfile.py < prev    next >
Text File  |  2001-05-03  |  2KB  |  76 lines

  1. #! /usr/local/bin/python
  2. #
  3. # The Python Imaging Library.
  4. # $Id$
  5. #
  6. # a utility to identify image files
  7. #
  8. # this script identifies image files, extracting size and
  9. # pixel mode information for known file formats.  Note that
  10. # you don't need the PIL C extension to use this module.
  11. #
  12. # History:
  13. # 0.0 1995-09-01 fl   Created
  14. # 0.1 1996-05-18 fl   Modified options, added debugging mode
  15. # 0.2 1996-12-29 fl   Added verify mode
  16. # 0.3 1999-06-05 fl   Don't mess up on class exceptions (1.5.2 and later)
  17. #
  18.  
  19. import Image
  20.  
  21. import getopt, sys
  22.  
  23. if len(sys.argv) == 1:
  24.     print "PIL File 0.3/99-06-05 -- identify image files"
  25.     print "Usage: pilfile [option] files..."
  26.     print "Options:"
  27.     print "  -f  list supported file formats"
  28.     print "  -i  show associated info and tile data"
  29.     print "  -v  verify file headers"
  30.     print "  -q  quiet, don't warn for unidentified/missing/broken files"
  31.     sys.exit(1)
  32.  
  33. try:
  34.     opt, argv = getopt.getopt(sys.argv[1:], "fqivD")
  35. except getopt.error, v:
  36.     print v
  37.     sys.exit(1)
  38.  
  39. verbose = quiet = verify = 0
  40.  
  41. for o, a in opt:
  42.     if o == "-f":
  43.         Image.init()
  44.         id = Image.ID[:]
  45.         id.sort()
  46.         print "Supported formats:"
  47.         for i in id:
  48.             print i,
  49.         sys.exit(1)
  50.     elif o == "-i":
  51.         verbose = 1
  52.     elif o == "-q":
  53.         quiet = 1
  54.     elif o == "-v":
  55.         verify = 1
  56.     elif o == "-D":
  57.         Image.DEBUG = Image.DEBUG + 1
  58.  
  59. for file in argv:
  60.     try:
  61.         im = Image.open(file)
  62.         print "%s:" % file, im.format, "%dx%d" % im.size, im.mode,
  63.         if verbose:
  64.             print im.info, im.tile,
  65.         print
  66.         if verify:
  67.             try:
  68.                 im.verify()
  69.             except:
  70.                 if not quiet:
  71.                     print "failed to verify image",
  72.                     print "(%s:%s)" % (sys.exc_type, sys.exc_value)
  73.     except IOError, v:
  74.         if not quiet:
  75.             print file, "failed:", v
  76.