root / pkpgcounter / trunk / pkpgpdls / pil.py @ 3456

Revision 3436, 2.0 kB (checked in by jerome, 16 years ago)

Removed spaces at EOL.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1# -*- coding: utf-8 -*-
2#
3# pkpgcounter : a generic Page Description Language parser
4#
5# (c) 2003, 2004, 2005, 2006, 2007, 2008 Jerome Alet <alet@librelogiciel.com>
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program.  If not, see <http://www.gnu.org/licenses/>.
18#
19# $Id$
20#
21
22"""This modules implements a page counter for image formats supported by the Python Imaging Library."""
23
24import pdlparser
25
26try :
27    from PIL import Image
28except ImportError :
29    sys.stderr.write("ERROR: You MUST install the Python Imaging Library (python-imaging) for pkpgcounter to work.\n")
30    raise pdlparser.PDLParserError, "The Python Imaging Library is missing."
31
32import version
33
34class Parser(pdlparser.PDLParser) :
35    """A parser for plain text documents."""
36    totiffcommands = [ 'convert "%(infname)s" "%(outfname)s"' ]
37    required = [ "convert" ]
38    def isValid(self) :
39        """Returns True if data is an image format supported by PIL, else False."""
40        try :
41            image = Image.open(self.filename)
42        except (IOError, OverflowError) :
43            return False
44        else :
45            self.format = "%s (%s)" % (image.format, image.format_description)
46            return True
47
48    def getJobSize(self) :
49        """Counts pages in an image file."""
50        index = 0
51        image = Image.open(self.filename)
52        try :
53            while True :
54                index += 1
55                image.seek(index)
56        except EOFError :
57            pass
58        return index
Note: See TracBrowser for help on using the browser.