Shrinking PNG image size?

The place for chatting and discussing subjects unrelated to Wesnoth.

Moderator: Forum Moderators

Post Reply
User avatar
Pentarctagon
Project Manager
Posts: 5564
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Shrinking PNG image size?

Post by Pentarctagon »

Maybe a simple question, or maybe not; but how would one go about reducing the size of a PNG image, assuming it's a regular 32-bit/RGBA image? As I understand it, PNGs already "compress" themselves by taking all the existing colors in an image and mapping them to a smaller representation of that color, and then using that representation rather than the full 32-bits per RGBA pixel, but I'm curious if there are any ways to further reduce size. Using normal compression methods (gzip, 7z/LZMA, etc) tend to actually increase the file's size, while converting the image to text and compressing with 7zip/PPMd (very good for text compression) results in a smaller file than the regular PNG. For example, Wesnoth's ancient wose portrait is 196 kb, while converting it to text and compressing with PPMd results in a 174.5 kb file, so I assume that further size reduction must be possible in a fair number of cases.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
User avatar
zookeeper
WML Wizard
Posts: 9742
Joined: September 11th, 2004, 10:40 pm
Location: Finland

Re: Shrinking PNG image size?

Post by zookeeper »

If you mean aside from running them through an optimizer (which is already occasionally done for mainline images), then not much. If the optimizer being used is set to preserve color information in fully transparent pixels, then one can help it along by making sure all such pixels have a uniform color (instead of random rgb values plastered all over the place, which can easily happen), but I'd think most if not all the best optimizers at least have a toggle for letting them modify fully transparent pixels when needed.

There's also pngquant for lossy compression, but the few times I've tried it I didn't seem to get very good results. But I don't quite remember what kind of images I used it on.

EDIT: I personally use zopflipng for all my Wesnoth needs.
gnombat
Posts: 706
Joined: June 10th, 2010, 8:49 pm

Re: Shrinking PNG image size?

Post by gnombat »

What do you mean by "converting the image to text"?
User avatar
doofus-01
Art Director
Posts: 4128
Joined: January 6th, 2008, 9:27 pm
Location: USA

Re: Shrinking PNG image size?

Post by doofus-01 »

May I ask what spurred this question? I'm not challenging your question, but if every little stored charge matters, then maybe pixel art is still relevant or at least lossy storage, such as fewer colors or JPG, could be acceptable? At least it could be if the alternative is a lot of effort and study to get an additional 7% compression on a < 200 kb PNG...
BfW 1.12 supported, but active development only for BfW 1.13/1.14: Bad Moon Rising | Trinity | Archaic Era |
| Abandoned: Tales of the Setting Sun
GitHub link for these projects
User avatar
Pentarctagon
Project Manager
Posts: 5564
Joined: March 22nd, 2009, 10:50 pm
Location: Earth (occasionally)

Re: Shrinking PNG image size?

Post by Pentarctagon »

zookeeper wrote:If you mean aside from running them through an optimizer (which is already occasionally done for mainline images), then not much. If the optimizer being used is set to preserve color information in fully transparent pixels, then one can help it along by making sure all such pixels have a uniform color (instead of random rgb values plastered all over the place, which can easily happen), but I'd think most if not all the best optimizers at least have a toggle for letting them modify fully transparent pixels when needed.

There's also pngquant for lossy compression, but the few times I've tried it I didn't seem to get very good results. But I don't quite remember what kind of images I used it on.

EDIT: I personally use zopflipng for all my Wesnoth needs.
Alright, thanks!
gnombat wrote:What do you mean by "converting the image to text"?
I mean literally, taking the pixel data and converting it to a hex string. So, a solid red would be "FF0000FF".
doofus-01 wrote:May I ask what spurred this question? I'm not challenging your question, but if every little stored charge matters, then maybe pixel art is still relevant or at least lossy storage, such as fewer colors or JPG, could be acceptable? At least it could be if the alternative is a lot of effort and study to get an additional 7% compression on a < 200 kb PNG...
I've been trying to get into learning Rust, and decided to try writing out image data as plaintext (using an existing library to read the PNG data). I'd done a little research about different types of compression before, and knew that PPMd was good for text, so I tried compressing my plaintext image with it. I had expected it to compress pretty well, since it's a lot of highly repetitive data, but I wasn't expecting it to get smaller than the original PNG image especially when compressing the PNG with bzip2/LZMA/etc actually made it a bit larger.
99 little bugs in the code, 99 little bugs
take one down, patch it around
-2,147,483,648 little bugs in the code
Post Reply