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

PNG compression #14

Closed
camsjams opened this issue Jan 16, 2015 · 7 comments
Closed

PNG compression #14

camsjams opened this issue Jan 16, 2015 · 7 comments

Comments

@camsjams
Copy link

Thanks for the great library (I migrated from https://github.com/fzaninotto/screenshot-as-a-service).

Is there a way to modify the PNG compression? Or perhaps the color palette?

When I take a screenshot of a black and white document with pure text on a white background, the resulting PNG file is still well over 1MB.

When I use the JPEG or PDF compression, the file is much smaller.

Any tips?

@vbauer
Copy link
Owner

vbauer commented Feb 20, 2015

Yes, I faced with this issue. It looks like you use PhantomJS as an engine for Manet.

I've just make some test with the following request: http://localhost:8891/?url=https%3A%2F%2Fgithub.com%2Fvbauer%2Fmanet&force=true (it is the Github page of Manet) and got the following results:

  • PhantomJS: 39.8 MB
  • SlimerJS: 1.3 MB

Is it OK for you to switch engine to SlimerJS (as temporary workaround)?

I need some time to research possibilities of some compression library (like this one: https://github.com/imagemin/imagemin)

vbauer added a commit that referenced this issue Feb 20, 2015
@vbauer
Copy link
Owner

vbauer commented Feb 20, 2015

I've just integrated imagemin and added compressing for the following formats: JPEG, PNG, GIF, SVG.

It shown the following results for the same page (PNG format):

  • PhantomJS: 892 KB
  • SlimerJS: 973 KB

I think the result is pretty good, but it takes additional time for compressing.
Compression is switched off by default, to enable it use --compress true.

@vbauer vbauer closed this as completed Feb 20, 2015
@vbauer vbauer reopened this Feb 21, 2015
@vbauer
Copy link
Owner

vbauer commented Feb 21, 2015

Imagemin is a good compressor, but the main problem in the "quality" parameter..

@vbauer
Copy link
Owner

vbauer commented Feb 21, 2015

It looks like I've found the problem. PhantomJS documentation contains mistake: http://phantomjs.org/api/webpage/method/render.html

quality parameter is "An integer between 0 and 100" and in example they use String type. The worst moment that Integer value works fine with JPEG, but doesn't work with PNG.

I've committed new fix, now it should work fine without compress parameter.

@vbauer vbauer closed this as completed Feb 21, 2015
vbauer added a commit that referenced this issue Feb 21, 2015
@jfix
Copy link

jfix commented Feb 21, 2015

I guess it hasn't arrived on npm yet, because updating it doesn't make a change for me (using the --compression true or --compress true parameter). Google.com is still 3.0 MB in size. Any way I can verify I have the right version?

Oops: Just noticed that I was getting the cached version of the screenshot. Setting the --cache=-1 served freshly made screenshots. From 3.0MB to 22KB: FTW! Thanks a lot for you work!

Which also means that it has been published on npm (and it says that you published it 'one day ago': https://www.npmjs.com/package/manet), and that I have the latest version.

However, I still have to explicitly set the --compress true parameter, it doesn't seem to be the default. Without it, I get fat screenshots.

@vbauer
Copy link
Owner

vbauer commented Feb 21, 2015

Actually, --compress parameter works slow for really big screenshots (ex: 1024x20000), so I decided to switch it off by default.

In the next release all PNG images should be much smaller (even without this parameter) and --compress will be as an extra compression option.

@camsjams
Copy link
Author

Thanks @vbauer for making this update - it helps out a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants