8000 Jpeg quality 95 by default with rendering with PIL by dhyams · Pull Request #1771 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Jpeg quality 95 by default with rendering with PIL #1771

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

Merged
merged 10 commits into from
Apr 23, 2013
Prev Previous commit
Next Next commit
Added jpeg quality support for gtk backend
  • Loading branch information
Daniel Hyams committed Apr 19, 2013
commit 05fc06dab4758ce14ff7d32ce297a711b20a2611
15 changes: 12 additions & 3 deletions lib/matplotlib/backends/backend_gtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ def print_jpeg(self, filename, *args, **kwargs):
def print_png(self, filename, *args, **kwargs):
return self._print_image(filename, 'png')

def _print_image(self, filename, format):
def _print_image(self, filename, format, *args, **kwargs):
if self.flags() & gtk.REALIZED == 0:
# for self.window(for pixmap) and has a side effect of altering
# figure width,height (via configure-event?)
Expand All @@ -469,17 +469,26 @@ def _print_image(self, filename, format):
pixbuf.get_from_drawable(pixmap, pixmap.get_colormap(),
0, 0, 0, 0, width, height)

# set the default quality, if we are writing a JPEG.
# http://www.pygtk.org/docs/pygtk/class-gdkpixbuf.html#method-gdkpixbuf--save
options = cbook.restrict_dict(kwargs, ['quality'])
if format in ['jpg','jpeg']:
if 'quality' not in options:
options['quality'] = rcParams['savefig.jpeg_quality']
options['quality'] = str(options['quality'])

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP8: Please use just one newline between blocks of code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mean between lines 477 and 478?


if is_string_like(filename):
try:
pixbuf.save(filename, format)
pixbuf.save(filename, format, options=options)
except gobject.GError as exc:
error_msg_gtk('Save figure failure:\n%s' % (exc,), parent=self)
elif is_writable_file_like(filename):
if hasattr(pixbuf, 'save_to_callback'):
def save_callback(buf, data=None):
data.write(buf)
try:
pixbuf.save_to_callback(save_callback, format, user_data=filename)
pixbuf.save_to_callback(save_callback, format, user_data=filename, options=options)
except gobject.GError as exc:
error_msg_gtk('Save figure failure:\n%s' % (exc,), parent=self)
else:
Expand Down
0