Menu

#325 PNG file size get larger after processed by GM

v1.0_(example)
open
5
2016-09-19
2015-11-04
alien
No

I encountered some PNG images, all of which look right in common browsers or system photo viewer.
After processed by the GM (just read then write, with no other process), the file size gets much larger than original. I don't know what has happened. Is the png8's alpha channel (all these 3 PNG have full alpha channel, 0-255, not 0/255) making it ?

1 Attachments

Discussion

  • Glenn Randers-Pehrson

    This is a known problem. The images have 256 colors, and GM inserts a bKGD chunk which requires an additional slot in the palette if the background color isn't present in the image. As a result, GM writes a PNG32 instead of an indexed PNG8 output.

    The workaround is to use the "-background [color]" option to specify a color that is present in the image. The problematic images usually come from running "pngquant" to create a 256-color image. The problem doesn't arise when "pngquant" specifies 255 instead of 256 as the desired number of colors.

     

    Last edit: Glenn Randers-Pehrson 2015-11-04
    • alien

      alien - 2015-11-05

      Thanks for reply. I'll test 255 color with pngquant, for I want to have my PNG image compressed.

       
    • alien

      alien - 2015-11-09

      I have tried what you said.
      I have a png file 'pngtest2.png', 269KB.
      I generated a compressed png file 'pngtest2-255.png' with setting the colors number 255, 63.4KB.
      Command is;
      ./pngquant 255 pngtest2.png -o pngtest2-255.png
      And then, I process it using the following command:
      ./gm convert pngtest2-255.png pngtest2-255-gm.png
      Here, I got a PNG 'pngtest2-255-gm.png'. However, the file size is 173KB, much bigger than the pngtest2-255.png.

       
    • alien

      alien - 2015-11-09

      I have tested the png image posted in my last reply.
      In GM png.c line 2399:
      png_get_valid(ping, ping_info, PNG_INFO_tRNS)
      I do not know why if the image have tRNS chunks here, the GM do line 2465:
      image->storage_class=DirectClass;

      What should I do to get a compressed png file by pngquant, which also can be further processed by GM without larger filesize ?

      Hoping for your reply.

       

      Last edit: alien 2015-11-09
  • truedrog

    truedrog - 2016-09-19

    Hi! I can confrim the same behavior when trying to resize image which was process with pngquant.
    My command was gm -convert test-fs8.png -resize 75x% resized.png

    File got bigger 3x times. Is this a bug or expected output? If it is the former what should i do avoid such thing? I have many of images of png which were processed with pnguant at first and i need to resize them.

     

    Last edit: truedrog 2016-09-19
    • Bob Friesenhahn

      Bob Friesenhahn - 2016-09-19

      Please attach your PNG files in an archive wrapper like a zip archive
      because SourceForge re-writes all JPEG, PNG, and GIF files as soon as
      they are uploaded to the bug tracker. The re-write removes the
      important stuff we need to see.

      Bob

       
      • truedrog

        truedrog - 2016-09-19

        Yeah, I did it immediately after i uploaded them. They are now in zip archive attached to my post.

         

        Last edit: truedrog 2016-09-19
      • truedrog

        truedrog - 2016-09-20

        In case you didn't see my edit, here is my archive wrapper. Hope that helps.
        Sorry for bumping.

         

Log in to post a comment.