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

Preserve color palette for PNG images #4416

Closed
aitva opened this issue Feb 16, 2018 · 6 comments · Fixed by #4426
Closed

Preserve color palette for PNG images #4416

aitva opened this issue Feb 16, 2018 · 6 comments · Fixed by #4426
Assignees
Milestone

Comments

@aitva
Copy link

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 self-assigned this Feb 16, 2018
@bep bep added this to the v0.37 milestone Feb 16, 2018
@bep
Copy link
Member

bep commented Feb 16, 2018

@aitva
Copy link
Author

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
Copy link
Member

bep commented Feb 16, 2018

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

@aitva
Copy link
Author

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
Copy link
Member

bep commented Feb 19, 2018

Thanks for this, really appreciated.

@bep bep changed the title Add quality setting for PNG image Preserve color palette for PNG images Feb 19, 2018
bep added a commit to bep/hugo that referenced this issue Feb 19, 2018
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
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
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 as completed in #4426 Feb 19, 2018
bep added a commit that referenced this issue Feb 19, 2018
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
@github-actions
Copy link

github-actions bot commented Mar 7, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants