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