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
PS backend optionally jpeg-compresses the embedded images #1959
Conversation
@@ -196,7 +199,8 @@ class RendererPS(RendererBase): | |||
fontd = maxdict(50) | |||
afmfontd = maxdict(50) | |||
|
|||
def __init__(self, width, height, pswriter, imagedpi=72): | |||
def __init__(self, width, height, pswriter, imagedpi=72, | |||
compress_images=False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually prefer this as a kwarg, but I wonder if we shouldn't also make it an rcParam. There are other rcParams that control PS output (ps.usedistiller
for example).
Good work @leejjoon - I can see a really massive benefit to having compressed images in ths PS output. I've added a couple of comments, but generally I think this is a good improvement. 😄 |
@mdboom: yes, it will be natural to introduce a new rcParam. On the other hand, this kind of lossy compression of images are supported by other backends (pdf and svg) as far as I know. So I am more inclined to introduce a rather general parameter, rather than a ps-specific one. For example, "savefig.compress_images"? @pelson : yes, we'd better use the |
@leejjoon: Yes, let's introduce a general parameter, and over time we can add support for this sort of thing to other backends. What is the different parameter used for |
When "xpdf" distiller is used, the original ps file created by matplotlib is converted to a pdf file using ghostscript (ps2pdf) and then converted back to ps file using "pdftops". During the 1st step, the images are decompressed (if necessary) and then recompressed. During the 2nd step, the original compression seems to be reserved.
|
Looks potentially very useful, but I would prefer to make the lossy compression an image-by-image option, with an rcParam or keyword argument to set it for all images at once. I think it's quite reasonable to want to compress a photograph lossily and keep other bitmaps (e.g. results of MixedModeBackend rasterization) lossless. |
This seems useful (though not to me personally). |
Closing as abandoned. Feel free to re-open; does seem potentially useful (though pdf does this by default - do any journals bork at PDF these days?) |
This PR is to enable the postscript backend to jpeg-compress the embedded images (other artists like texts are untouched, i.e., they are still in vector format). This can significantly reduce the file size of postscript output (of course the image quality will be degraded), which will be useful for sites like arxiv.org.
The compression is done when the eps file is created by matplolib (it uses PIL), or when the postscript file is distilled (only "xpdf" distiller is supported, I could not figure out how to do this with "ghostscript distiller").