pilfile.py :  » GUI » Python-Image-Library » Imaging-1.1.7 » Scripts » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » GUI » Python Image Library 
Python Image Library » Imaging 1.1.7 » Scripts » pilfile.py
#! /usr/local/bin/python
#
# The Python Imaging Library.
# $Id$
#
# a utility to identify image files
#
# this script identifies image files, extracting size and
# pixel mode information for known file formats.  Note that
# you don't need the PIL C extension to use this module.
#
# History:
# 0.0 1995-09-01 fl   Created
# 0.1 1996-05-18 fl   Modified options, added debugging mode
# 0.2 1996-12-29 fl   Added verify mode
# 0.3 1999-06-05 fl   Don't mess up on class exceptions (1.5.2 and later)
# 0.4 2003-09-30 fl   Expand wildcards on Windows; robustness tweaks
#

import site
import getopt, glob, sys

from PIL import Image

if len(sys.argv) == 1:
    print "PIL File 0.4/2003-09-30 -- identify image files"
    print "Usage: pilfile [option] files..."
    print "Options:"
    print "  -f  list supported file formats"
    print "  -i  show associated info and tile data"
    print "  -v  verify file headers"
    print "  -q  quiet, don't warn for unidentified/missing/broken files"
    sys.exit(1)

try:
    opt, args = getopt.getopt(sys.argv[1:], "fqivD")
except getopt.error, v:
    print v
    sys.exit(1)

verbose = quiet = verify = 0

for o, a in opt:
    if o == "-f":
        Image.init()
        id = Image.ID[:]
        id.sort()
        print "Supported formats:"
        for i in id:
            print i,
        sys.exit(1)
    elif o == "-i":
        verbose = 1
    elif o == "-q":
        quiet = 1
    elif o == "-v":
        verify = 1
    elif o == "-D":
        Image.DEBUG = Image.DEBUG + 1

def globfix(files):
    # expand wildcards where necessary
    if sys.platform == "win32":
        out = []
        for file in files:
            if glob.has_magic(file):
                out.extend(glob.glob(file))
            else:
                out.append(file)
        return out
    return files

for file in globfix(args):
    try:
        im = Image.open(file)
        print "%s:" % file, im.format, "%dx%d" % im.size, im.mode,
        if verbose:
            print im.info, im.tile,
        print
        if verify:
            try:
                im.verify()
            except:
                if not quiet:
                    print "failed to verify image",
                    print "(%s:%s)" % (sys.exc_type, sys.exc_value)
    except IOError, v:
        if not quiet:
            print file, "failed:", v
    except:
        import traceback
        if not quiet:
            print file, "failed:", "unexpected error"
            traceback.print_exc(file=sys.stdout)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.