Skip to content

PNG compression level #2189

Closed
Closed

Description

@john-at-satlantic

Saved PNG images appear to have JPEG-like artifacts in Microsoft Paint and Microsoft Image Viewer. Probably due to those programs having trouble with compressed PNG.

The artifacts should go away if the compression level is reduced to 0 or 1.

Activity

  1. john-at-satlantic commented on Nov 30, 2017

    @john-at-satlantic
    Author

    Attached is screenshot of a saved file: on the left in Irfanview, on the right in Microsoft Photo Viewer.

    png-compare-2

  2. etpinard commented on Nov 30, 2017

    @etpinard
    Contributor

    Is that something we can do using browser-side canvas.toDataURL?

    I found https://www.npmjs.com/package/canvas-png-compression but it seems like a half/hacky solution.


    In the meantime, I'll recommend using

    Plotly.toImage(gd, { scale: /* something greater than 1 */))

    added in #1979 to scale up your exports.

  3. john-at-satlantic commented on Nov 30, 2017

    @john-at-satlantic
    Author

    https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toDataURL
    describes quality option only available for jpeg and webp. Otherwise quality = 0.92, which may be below the threshold of what I was hoping to achieve.

    It is worthwhile trying the scale option.

  4. etpinard commented on Dec 1, 2017

    @etpinard
    Contributor

    https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/toDataURL
    describes quality option only available for jpeg and webp

    Nice find. Thanks for the link!


    I can't guarantee we'll come up with a solution to this ticket. But thanks for pointing this out.

  5. alexcjohnson commented on Dec 1, 2017

    @alexcjohnson
    Collaborator

    My impression was PNGs use lossless compression so if your viewer can comprehend the image at all, it will get it perfectly correct, right? PNG compression really just seems to be an optimization process potentially trading file size for CPU cycles, but without changing the outcome.

    I wonder if the difference here is just how these different applications choose to display scaled-up pixels. Applications meant for editing (Paint, and seems like this has spilled over into MS Photo Viewer) might opt to show each pixel as a brick of constant color, while applications tuned more for viewing (Irfanview) smooth this out and may even try to infer subpixel information from neighboring pixels.

    If that's the case, this issue is not within the purview of plotly.js at all. If not, can you give an example of another application that performs better when compared at the same zoom level in Irfanview vs MSPV?

  6. alexcjohnson commented on Dec 6, 2017

    @alexcjohnson
    Collaborator

    @john-at-satlantic feel free to reopen if ^^ does not capture what's happening here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugsomething broken

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions