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

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

Changed coding statement to please this fucking Emacs.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
RevLine 
[3410]1# -*- coding: utf-8 -*-
[412]2#
3# pkpgcounter : a generic Page Description Language parser
4#
[564]5# (c) 2003, 2004, 2005, 2006, 2007, 2008 Jerome Alet <alet@librelogiciel.com>
[463]6# This program is free software: you can redistribute it and/or modify
[412]7# it under the terms of the GNU General Public License as published by
[463]8# the Free Software Foundation, either version 3 of the License, or
[412]9# (at your option) any later version.
[463]10#
[412]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
[463]17# along with this program.  If not, see <http://www.gnu.org/licenses/>.
[412]18#
19# $Id$
20#
21
[500]22"""This modules implements a page counter for image formats supported by the Python Imaging Library."""
[412]23
[527]24import pdlparser
[500]25
[527]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
[412]32import version
33
34class Parser(pdlparser.PDLParser) :
35    """A parser for plain text documents."""
[527]36    totiffcommands = [ 'convert "%(infname)s" "%(outfname)s"' ] 
37    required = [ "convert" ]
[412]38    def isValid(self) :   
[500]39        """Returns True if data is an image format supported by PIL, else False."""   
40        try :
[522]41            image = Image.open(self.filename)
[518]42        except (IOError, OverflowError) :   
[414]43            return False
[500]44        else :   
[555]45            self.format = "%s (%s)" % (image.format, image.format_description)
[500]46            return True
[412]47           
48    def getJobSize(self) :
[500]49        """Counts pages in an image file."""
50        index = 0
[522]51        image = Image.open(self.filename)
[500]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.