-1

I need to compress PNG images on PC for data transmission in Python, transfer it to mobile and read it there in Java. I need lossless compression.

The hard part is compression and decompression in different environments and programming languages. I need to use something available for both languages. I've tried zlib, which technically should work, but it only decreases size by about 0.001% (with "best" compression setting 9).

  1. What am I doing wrong with zlib, if anything?
  2. What are the possible alternatives?
  3. Is there any other way to go about this problem? I just need to transfer data as byte stream and the compression was my first thought to optimizing it.
qalis
  • 1,314
  • 1
  • 16
  • 44
  • 1
    **Hint:** Are you trying to compress a file that's already compressed? – Robert Harvey Dec 16 '19 at 22:32
  • PNG is a lossless image compression format. Compressing it again is unlikely to yield smaller files. – Elliott Frisch Dec 16 '19 at 22:32
  • @RobertHarvey yes, I am aware that PNG is compressed in some way already. I was just hoping there is *some* way to reduce image size in any way. If I really have to, I will do lossy compression, though I want to avoid it if I can, even it if means really subpar compression. I managed to get to 0.8% compression at most. – qalis Dec 16 '19 at 22:40
  • Your PNG is already compressed as much as it will go without resorting to lossy compression or image reduction. – Robert Harvey Dec 16 '19 at 22:41
  • @RobertHarvey well, that's a shame... thanks. – qalis Dec 16 '19 at 22:44
  • PNG uses DEFLATE (which is an non patent encumbered compressor); it would be possible to decompress your PNG and then re-compress it with a different algorithm. I would not expect results much better than PNG, if you need to reduce the image size in a meaningful way then lossy compression and possibly image scaling and/or color reduction (which are *just* other ways of saying lossy) is the only option. – Elliott Frisch Dec 16 '19 at 22:51

1 Answers1

1

compressing a a compressed file (like png / jpg) will normally not yield a lot and can even occasionally increase the file size. It's not worth the effort.

gelonida
  • 5,327
  • 2
  • 23
  • 41