ReptarX / pyfpdf

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

Cannot import GIF files that don't have transparency. #33

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Try adding a gif that doesn't have transparency to a pdf, such as on the 
next line.
2. pdf.image("foo.gif")
3. Errors out (don't remember specifics, already patched my local copy).

What is the expected output? What do you see instead?
The GIF that has no transparency channel should be added to the page. Instead, 
fpdf fails with an error.

What version of the product are you using? On what operating system?
Newest copy from pip (not exactly sure, but the bug appears to still exist in 
your trunk).

Please provide any additional information below.
The error happens in def _parsegif(self, filename):   when trying to run 
transparency = im.info['transparency'].

The corrected code is in the first attachment. I have also uploaded an example 
gif to help demonstrate the problem. On my patched copy (with the fixed code 
from the attachment), it now tries to add the transparency parameter, and if it 
fails, it continues instead without adding the transparency parameter.

Original issue reported on code.google.com by hardy.ke...@gmail.com on 5 Dec 2012 at 12:32

Attachments:

GoogleCodeExporter commented 9 years ago
Hello Hardy:

Thanks for the report, could you send a patch in a diff format?
Also, if you can include a test case that would help too, i.e.:

http://code.google.com/p/pyfpdf/source/browse/tests/issue14.py

If you want, I can give you commit access so you can send your changes directly.

Original comment by reingart@gmail.com on 5 Dec 2012 at 4:01

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
I created the patch file. I haven't created the test case yet however. I'll 
have to mess with that later. 

Original comment by hardy.ke...@gmail.com on 7 Dec 2012 at 10:30

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks, it is more clean now.

Maybe f.close should be in the finally clause (or outside the exception block).
It is a bit repetitive.
I think it could be closed just after getting the name (f.name).

Also, please try to catch the exact exception (ValueError or whatever PIL is 
raising, to avoid side-effects with IOErrors and other problems).

Original comment by reingart@gmail.com on 8 Dec 2012 at 4:26

GoogleCodeExporter commented 9 years ago
Why not to test key "transparency" in info list
like

f = tempfile.NamedTemporaryFile(delete=False, suffix=".png")
tmp = f.name
f.close()
if "transparency" in im.info:
    transparency = im.info['transparency']
    im.save(tmp, transparency=transparency)
else:
    im.save(tmp)    
info = self._parsepng(tmp)

Original comment by romiq...@gmail.com on 8 Jan 2013 at 11:56

GoogleCodeExporter commented 9 years ago
yes romiq.kh, your patch looks better, it would be wise to make a test with 
this gif file, sorry I didin't have time...

Original comment by reingart@gmail.com on 8 Jan 2013 at 4:33

GoogleCodeExporter commented 9 years ago
hardy.kevin.c, can we use this sample gif as example?

Propose + test + test images in attachment

Original comment by romiq...@gmail.com on 9 Jan 2013 at 11:44

Attachments:

GoogleCodeExporter commented 9 years ago
This test requires two additional GIF pictures:

1. put them (maybe repaint) in examples folder?
2. generate from test file on-the-fly?
3. or Something Completely Different?

Original comment by romiq...@gmail.com on 18 Jan 2013 at 12:21

GoogleCodeExporter commented 9 years ago
Sorry, I don't fully understand. 
I think you can copy all required files in the test or example directory.

Original comment by reingart@gmail.com on 18 Jan 2013 at 3:58

GoogleCodeExporter commented 9 years ago
So, this slightly updated test code. No external gif file required.
Standalone test file also included.

Can i merge this?

Original comment by romiq...@gmail.com on 22 Jan 2013 at 11:02

Attachments:

GoogleCodeExporter commented 9 years ago
Oops, forgot about first line description in issue33.py.

Original comment by romiq...@gmail.com on 22 Jan 2013 at 11:05

Attachments:

GoogleCodeExporter commented 9 years ago
It looks nice!go ahead with the commit to close this issue, thanks to all for 
the collaboration.

Original comment by reingart@gmail.com on 22 Jan 2013 at 2:36

GoogleCodeExporter commented 9 years ago
Fixes committed.

Original comment by romiq...@gmail.com on 22 Jan 2013 at 7:06