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

Preserve color palette for PNG images #4416

Closed
aitva opened this Issue Feb 16, 2018 · 5 comments

Comments

Projects
None yet
2 participants
@aitva

aitva commented Feb 16, 2018

Original post on Discourse.

On my website, the PNG images resized with Hugo are bigger than the original.

For example, with an image called apercu-slack.png:

  • the original is 1280x920px and weight 26ko
  • the resized version is 1024x736px and weight 60ko

The original image:
apercu-slack

The resized version:
apercu-slack_hu44f56606ae01ef68f036029c27b3bc23_26297_1024x0_resize_box

@bep bep added the Enhancement label Feb 16, 2018

@bep bep self-assigned this Feb 16, 2018

@bep bep added this to the v0.37 milestone Feb 16, 2018

@bep

This comment has been minimized.

Member

bep commented Feb 16, 2018

@aitva

This comment has been minimized.

aitva commented Feb 16, 2018

I have made a repo to test the quality parameter of Golang's image/png library. I will try to add imaging and lossypng.

https://github.com/aitva/golang-png-encoding

@bep

This comment has been minimized.

Member

bep commented Feb 16, 2018

@aitva much appreciated. Note that imaging is only a shallow wrapper around err = png.Encode(w, img).

@aitva

This comment has been minimized.

aitva commented Feb 19, 2018

Hi, I've spent some time toying with the image library and here is what I found:

  • just encoding and decoding the PNG image through go increases its size
  • the PNG image I am using comes with a color palette, which greatly reduce its size
  • passing the image through imaging removes its color palette, greatly increasing its size
  • using the lossypng library does not help, the image quality is affected and the image size increase

The good news is that there is an easy fix! We can reuse the original color palette on the reduced image.
Thus, we go back to something very close to the original size and the image is not altered:

  • original image: 1280x920px and 26297 bytes
  • original image through go: 1280x920px and 31368 bytes
  • resized image: 1024x736px and 47339 bytes
  • resized and indexed image: 1024x736px and 23617 bytes

There are more details at https://github.com/aitva/golang-png-encoding

@bep

This comment has been minimized.

Member

bep commented Feb 19, 2018

Thanks for this, really appreciated.

@bep bep changed the title from Add quality setting for PNG image to Preserve color palette for PNG images Feb 19, 2018

bep added a commit to bep/hugo that referenced this issue Feb 19, 2018

resource: Preserve color palette for PNG images
This commit will force a reprocessing of PNG images with new names, so it is adviced to run a `hugo --gc` to remove stale files.

Fixes gohugoio#4416

bep added a commit to bep/hugo that referenced this issue Feb 19, 2018

resource: Preserve color palette for PNG images
This commit will force a reprocessing of PNG images with new names, so it is adviced to run a `hugo --gc` to remove stale files.

Fixes gohugoio#4416

bep added a commit to bep/hugo that referenced this issue Feb 19, 2018

resource: Preserve color palette for PNG images
This commit will force a reprocessing of PNG images with new names, so it is adviced to run a `hugo --gc` to remove stale files.

Fixes gohugoio#4416

@bep bep closed this in #4426 Feb 19, 2018

bep added a commit that referenced this issue Feb 19, 2018

resource: Preserve color palette for PNG images
This commit will force a reprocessing of PNG images with new names, so it is adviced to run a `hugo --gc` to remove stale files.

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