PNG Compression Level

889 views
Skip to first unread message

simran

unread,
Jul 17, 2015, 4:38:17 AM7/17/15
to golang-nuts
Hi All, 

When i am outputting a png, it appears it gets automatically compressed. 

However, i'm not quite sure how to ensure it does not. 

The relevant bit of my code is: 

import (
"image/png"
)
imgResized := resize.Resize(newImageWidth, 0, srcImage, resize.MitchellNetravali)
png.Encode(outfile, imgResized)


Would appreciate any help on setting the compression level to zero. 

thanks,

simran.

Jan Mercl

unread,
Jul 17, 2015, 5:06:52 AM7/17/15
to golang-nuts
On Fri, Jul 17, 2015 at 10:38 AM simran <sim...@dn.gs> wrote:

> Would appreciate any help on setting the compression level to zero.

What's to reason? PNG compression is lossless.

--

-j

simran

unread,
Jul 17, 2015, 5:12:24 AM7/17/15
to Jan Mercl, golang-nuts
That's what i thought, but the encoding is producing images that sometimes have a very slight colour shift... so just want to try without any compression to see what happens. 

--

-j

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jan Mercl

unread,
Jul 17, 2015, 5:26:28 AM7/17/15
to golang-nuts
On Fri, Jul 17, 2015 at 11:12 AM simran <sim...@dn.gs> wrote:

> That's what i thought, but the encoding is producing images that sometimes have a very slight colour shift... so just want to try without any compression to see what happens.

I'd suggest to write small program which compresses a bitmap to PNG, decompresses the result back to another bitmap and compare it to the original pixels one by one.

If you find an example which fail this test then please fill an issue with the full source code for the test program and the source picture attached.
--

-j

James Bardin

unread,
Jul 17, 2015, 9:08:11 AM7/17/15
to golan...@googlegroups.com, 0xj...@gmail.com


On Friday, July 17, 2015 at 5:12:24 AM UTC-4, simran g wrote:
That's what i thought, but the encoding is producing images that sometimes have a very slight colour shift... so just want to try without any compression to see what happens. 


Are you certain that the images with a color shift don't have an embedded ICC profile, or color palette? (or possibly even gamma and chromacity values)

Carlos Castillo

unread,
Jul 17, 2015, 11:56:23 AM7/17/15
to golan...@googlegroups.com
You can set the compression level by making a image/png.Encoder value, setting it's CompressionLevel field (NoCompression is -1), and using it's Encode method. (RTFM: http://golang.org/pkg/image/png/#Encoder)

That being said, as suggested by the other posts, Compression in PNG is done by zlib, which is a lossless file encoding, so changing it's level shouldn't affect pixel color in any way.

Michael Jones

unread,
Jul 17, 2015, 1:00:09 PM7/17/15
to James Bardin, golang-nuts, 0xj...@gmail.com
http://koti.kapsi.fi/juanttil/profiletest/

simple test images

— 
Michael Jones, CEO  •  mic...@wearality.com  •  +1 650 656-6989 
Wearality Corporation  •  289 S. San Antonio Road  •  Los Altos, CA 94022

Reply all
Reply to author
Forward
0 new messages