reingart / pyfpdf_googlecode

Automatically exported from code.google.com/p/pyfpdf
GNU Lesser General Public License v3.0
0 stars 0 forks source link

twitter.png error #65

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Make a simple app with this web2py slice 
http://www.web2pyslices.com/slice/show/1598/simplest-pdf-output-ever-thanks-to-f
pdf
2. Copy [app]/static/images/twitter.png [app]/static/images/fpdf.png
3. Run app

What is the expected output? What do you see instead?
A long error ticket which ends with the following

  File "...\gluon\contrib\fpdf\fpdf.py", line 1788, in _parsepng
    color += re.sub('(.{3}).',lambda m: m.group(1),line, flags=re.DOTALL)
  File "...\python\lib\re.py", line 151, in sub
    return _compile(pattern, flags).sub(repl, string, count)
RuntimeError: internal error in regular expression engine

Ticket details:
File ...\python\lib\re.py in sub at line 151 
Function argument list

(pattern='(.{3}).', repl=<function <lambda>>, 
string='\x00\x00\x00\x00\x00\x00\x00\x00\x7f\xbe\xd0_\x0f\t\t\x80\x15\r\r 
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
\x00\x00\x00\x00\x00\x00\x00\x00...\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
x00\x00\xeb\xf3\xf3\xe0\xf1\xf7\xf7\x80\x81B0\xa1\x00\x00\x00\x00', count=0, 
flags=16)

Code listing

151. return _compile(pattern, flags).sub(repl, string, count)

Variables

count   0
string  '\x00\x00\x00\x00\x00\x00\x00\x00\x7f\xbe\xd0_\x0f\t\t\x80\x15\r\r 
\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00
\x00\x00\x00\x00\x00\x00\x00\x00...\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\
x00\x00\xeb\xf3\xf3\xe0\xf1\xf7\xf7\x80\x81B0\xa1\x00\x00\x00\x00'
pattern     '(.{3}).'
repl    <function <lambda>>
).sub   undefined
flags   16
global _compile     <function _compile>

What version of the product are you using? On what operating system?
the fpdf version bundled with web2py 2.6.4-stable+timestamp.2013.09.27.13.07.13 
(Rocket 1.2.6, Python 2.7.5)
running in web2py.exe on Windows XP Pro SP3 

Please provide any additional information below.

When I change fpdp.png to be a copy of glyphicons-halflings.png in the same 
folder this error doesn't occur.

Original issue reported on code.google.com by step.l...@gmail.com on 28 Oct 2013 at 12:24

GoogleCodeExporter commented 9 years ago
Never mind it, false positive. Twitter.png's color-depth is 32-bit, which 
according to your wiki isn't supported. Maximum supported png color-depth is 
24-bit.

Original comment by step.l...@gmail.com on 29 Oct 2013 at 4:06

GoogleCodeExporter commented 9 years ago
It alpha channel should be supported in recents versions, did you download the 
lates source code from the repository?

Do you have PIL installed?

Original comment by reingart@gmail.com on 29 Oct 2013 at 6:03

GoogleCodeExporter commented 9 years ago
Yes, I have PIL installed, why does FPDF rely on it?
As for source code, I'm using the whatever - I think it's actually 1.7.1 - FPDF 
version bundled with web2py 2.6.4-stable in contrib/fpdf. Are you suggesting I 
should  download the FPDF source and replace contrib/fpdf? Thanks. 

Original comment by step.l...@gmail.com on 29 Oct 2013 at 6:51

GoogleCodeExporter commented 9 years ago
I checked the latest source in here (August 15, 2013 
http://code.google.com/p/pyfpdf/source/detail?r=28db709a13315b59a487f7e8d0c4b15c
2e4e1043) against the source code bundled with web2py; the fpdf folders appear 
to be identical.

Original comment by step.l...@gmail.com on 29 Oct 2013 at 7:07

GoogleCodeExporter commented 9 years ago
PIL is need for jpg and gif support, but this is not your case.
You could use PIL to convert the image to a supported format (maybe a patch 
about that could be included in fpdf).

1.7.1 is recent enough

Closing this by now, thanks for reporting it !

Original comment by reingart@gmail.com on 29 Oct 2013 at 7:14

GoogleCodeExporter commented 9 years ago
I encountered this issue just recently when loading certain PNGs under 64-bit 
Windows 7. I resolved it by changing the regular expressions to avoid the 
'.{3}' syntax, ie:

diff --git a/fpdf/fpdf.py b/fpdf/fpdf.py
index 00bedf8..5c0450a 100644
--- a/fpdf/fpdf.py
+++ b/fpdf/fpdf.py
@@ -1738,8 +1738,8 @@ class FPDF(object):
                     color += data[pos]
                     alpha += data[pos]
                     line = substr(data, pos+1, length)
-                    color += re.sub('(.{3}).',lambda m: m.group(1),line, 
flags=re.DOT
-                    alpha += re.sub('.{3}(.)',lambda m: m.group(1),line, 
flags=re.DOT
+                    color += re.sub('(...).',lambda m: m.group(1),line, 
flags=re.DOTA
+                    alpha += re.sub('...(.)',lambda m: m.group(1),line, 
flags=re.DOTA
             del data
             data = zlib.compress(color)
             info['smask'] = zlib.compress(alpha)

Original comment by aren...@aiotec.co.nz on 31 Oct 2013 at 3:49

GoogleCodeExporter commented 9 years ago
@ aren...@aiotec.co.nz, Bingo! I checked your patch with twitter.png on Windows 
XP and it works! Thank you.
I don't know how to reopen this issue for Mariano, so I'll open a new issue 
pointing here again.

Original comment by step.l...@gmail.com on 31 Oct 2013 at 4:29

GoogleCodeExporter commented 9 years ago
Mmm, after all Mariano hasn't closed this issue yet, so I won't resubmit it. He 
should be able to pick aren...@aiotec.co.nz's patch from here.

Original comment by step.l...@gmail.com on 31 Oct 2013 at 4:33

GoogleCodeExporter commented 9 years ago
This issue was closed by revision 557114b43eca.

Original comment by reingart@gmail.com on 5 Feb 2014 at 4:00