any way to save an image to 8-bit indexed png format?

1,282 views
Skip to first unread message

sleepy

unread,
Jul 12, 2016, 10:32:55 PM7/12/16
to golang-nuts
I need to shrink images to as small as possible with an acceptable quality.
found https://tinypng.com/ could convert the image to 8-bit indexed png, which is best fit my requirement.

however, I need to do this by my go program, any hints for this?

thanks in advance.

xiio...@gmail.com

unread,
Jul 13, 2016, 12:08:07 PM7/13/16
to golang-nuts
Have you tried converting a starting image - lets say in color.NRGBA palette to a new 8 bit palette image (eg there are two at https://golang.org/pkg/image/color/palette/ )

ie using  the function : func (p Palette) Convert(c Color) Color to convert the (32bit) image pixels to an 8 bit palette image.

and then passing this paletted image to the PNG.encode function like you would with any other image

??
[haven't actually checked if the PNG package will work with this - but this would be the way to go if supported]

Nigel Tao

unread,
Jul 13, 2016, 10:54:40 PM7/13/16
to xiio...@gmail.com, golang-nuts
On Thu, Jul 14, 2016 at 2:07 AM, <xiio...@gmail.com> wrote:
> [haven't actually checked if the PNG package will work with this - but this
> would be the way to go if supported]

The PNG package should work with this: https://play.golang.org/p/Sxl-nLnecy

sleepy

unread,
Jul 15, 2016, 1:54:59 AM7/15/16
to golang-nuts, xiio...@gmail.com
Thanks, I will try it.

在 2016年7月14日星期四 UTC+8上午10:54:40,Nigel Tao写道:
Reply all
Reply to author
Forward
0 new messages