Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug with figure.savefig(): using AGG, PIL, JPG and StringIO #962

Closed
agiliodev opened this issue Jun 22, 2012 · 4 comments
Closed

Bug with figure.savefig(): using AGG, PIL, JPG and StringIO #962

agiliodev opened this issue Jun 22, 2012 · 4 comments

Comments

@agiliodev
Copy link

Hello!

I have a project which requires me to render my figure to my IIS Web Server in JPG format (constraint due to an old browser).

Using AGG backend and saving file to a StringIO, you get an "unknown extension" Error

To reproduce:

import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt, StringIO

plt.plot([3,6,2,4,7,1])
dataStream = StringIO.StringIO()
plt.savefig(dataStream, format="jpg", dpi=140, quality=75)

Work-around "client-code"-side: giving a "name" attribute to the stream

dataStream = StringIO.StringIO()
setattr(dataStream, "name", "foo.jpg")

Fix in backend_bases.py:
Add the keyword-argument "format" and set it to "jpeg" in the print function

line 1819:
    def print_jpg(self, filename_or_obj, *args, **kwargs):
    #[...] function body
    #Replcace this line:
    return image.save(filename_or_obj, **options)
    #By this one:
    return image.save(filename_or_obj, format="jpeg", **options)

It might seem quick&dirty but the format information is lost on the print_method(...) call [which leads to print_jpg( )] in print_figure(...)

Thank you!

Python 2.7 Matplotlib 1.1.0 via Python(x,y) on Windows XP Pro

@WeatherGod
Copy link
Member

I could have sworn we fixed this issue before. Is this only an issue with jpegs, or does it happen with others like png?

@agiliodev
Copy link
Author

From what I've seen it seems to concern only the formats requiring PIL image.save( ), so I believe it would be only for JPG and TIF. PNG works like a charm "as is".

@cgohlke
Copy link
Contributor

cgohlke commented Jun 23, 2012

Sorry, ignore the previous messages. Github is somehow messing up the commits to my fork/branch.

@pelson
Copy link
Member

pelson commented Aug 19, 2012

Should be fixed in 1.2.x as a result of #970.

@pelson pelson closed this as completed Aug 19, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants