Menu

Reduce PNG tiles size... without loosing existing transparency

2026-07-27
3 days ago
  • Laurent Grenet

    Laurent Grenet - 2026-07-27

    Hi @r_x,

    in Mobac, when creating an atlas, we can choose a custom tile processing.
    We can in particular, choose to convert tiles in PNG 16 colors (on 4 bits). This works, and for some maps, color reduction is not at all a drawback (or at least is a very minor drawback compare to advantage of size reduction).

    Nevertheless, there is a MAJOR issue : If "original" tiles are natively in PNG including transparency, convert them to PNG 16 colors reduces their size... but REMOVE transparency.... that make them unusable if they are supposed to be an overlay.
    I am in particular thinking to Strava Heat Maps, that do not need a large number of colors, but definitively require to be "transparent".

    So, my question is the following : Could you provide in MOBAC a tile post-processing that convert PNG tiles to PNG 16 colors but KEEPING the existing transparency ? Maybe it's only a matter of parameter when calling the existing PNG converter ?
    It would be really great for a lot atlas supposed to be used as overlay layers in OruxMaps. Not only Strava heat maps, but also WayMarkTrails tracks, Cadastre parcels, and others...

     
    • r_x

      r_x - 2026-07-28

      Hi Laurent,

      MOBAC uses color quantizer of JAI for reducing the number of colors and this library has no alpha transparency support.

      With a little bit of help from Claude and Copilot I was able to get replace the JAI color quantization implementation with an transparency aware WuQuantizer for reducing to 16 or 256 colors. Also the PNG4bit writer was adapted to support transparency.

      I created an experimental release: Mobile Atlas Creator 2.3.3-png4-alpha.zip. Please see https://sourceforge.net/projects/mobac/files/Alpha%20and%20experimental/

      I don't have good map sources with transparencies to test so please give it a try and provide feedback if it works as expected.

       

      Last edit: r_x 2026-07-28
      • Laurent Grenet

        Laurent Grenet - 2026-07-28

        Hi @r_x
        once again, you are the best !
        Tested, and approved !

        FYI, I created two small atlases around my home (Briançon, southern french alps) of Strava heat map. Original file is 11.5 Mb, with processing "PNG 16 colors+transparency", it decrease down to 4 MB. More than 60% reduction.
        And with exactly the same quality level, from users standpoint.

        Same test with WayMarkTrail tracks, same result ! From 1252k to 680k
        The reduction is a little bit less ("only" 50%, but nevertheless 50% !) because a lot of tiles are completely empty, and then probably not really reduced. I had a look, empty tiles are even a little bit larger after processing : 243bytes vs 163

        I'm really impatient to have this evolution in official version !

        Once again, thanks you so much !

         

        Last edit: Laurent Grenet 2026-07-28
        • Laurent Grenet

          Laurent Grenet - 2026-07-28

          I did also some tests with maps that do not require transparency.
          I did them with OpenTopoMap source, that is natively in PNG format.
          Whatever the "old PNG 16" or the "new PNG 16 with transparency" is chosen, the result is exactly the same, both in size and in quality.
          And is better in size (equivalent in quality) than conversion in JPEG 80%

          And the best is that, at least for OTM maps, quality in PNG 16 is exactly equivalent with "native PNG" quality.

          The same with OpenStreetMap (that is also "natively" png)

          For both OTM and OSM, size reduction is around 50%

          With French IGN maps (these maps are "natively" in Jpeg), convert them in PNG 16 reduces a little bit the size, without reducing the quality. Nevertheless, in this last case, size reduction (between 5% and 6%) is not worth atlas generation time increase due to conversion.

           
          • r_x

            r_x - 2026-07-28

            Note that the version you have tested has no longer "the old 16 colors quantization version".
            That part has completly be replaced by the new version which is optionally transparency aware plus the 4bit png writer which is now also transparency aware. If the map has no transparency then the output will be the same for both 16 colors options.

             
  • Michael Bechtold

    That is extremely interesting! What does PNG 16 exactly mean? 16 colors only? Then I would not understand that the quality can be the same. Can one of you pls. explain? Thank you.
    Michael

     
    • Laurent Grenet

      Laurent Grenet - 2026-07-31

      When original tile uses no more than 16 colors, "reduction" to 16 colors do not change anything....
      It's the case of "heat map" of Strava, and also tracks of WayMarkTrails

      And for tiles of a OpenTopoMap and OSM Mapnik, I don't know how many colors they're embedding, surely more than 16, but what I can say is that the quality is maybe not the same on a theoretical standpoint, but degradation is very minor, and that the gain of file size worth largely (at my eyes at least !) the very minor loss of quality...

      See here an example :

       

      Last edit: Laurent Grenet 2026-07-31
    • Laurent Grenet

      Laurent Grenet - 2026-07-31

      To be honest, after a deeper check, even for tracks of WayMarkTrail, there is a little loss in precision. Not directly due to the number of colors, but the precision of drawing after conversion, is a little bit degraded.
      Nevertheless, here also, IMHO the very large gain of size is a lot and a lot worth this very light degradation.

      See examples below :

       
    • Laurent Grenet

      Laurent Grenet - 2026-07-31

      After more testing, there is at least one drawback that is annoying with OTM maps and PNG16 conversion, it is about hillshading. This is easily understandable, because a limited number of colors is not really compatible with a smooth gradient of the gray background.

      But since OTM maps do not have "transparency", we can also convert their PNG tiles in JPEG. And, according to my tests, JPEG-70 generate a file of quite the same size than PNG16. And the quality remains very good (no really visible degradation vs original on the screen of my smartphone). We can even go to JPEG-60, that reduces even more the map size, and the quality remains more than acceptable. Of course, if we go down to JPEG-30, size reduction is even more important, but quality degradation begins to be visible.

      On the other hand, for OSM maps (or other maps originally in PNG, but not including hillshading, or more generally speaking not including gradient of background colors), PNG16 remains a very good candidate.

      But for maps including transparency, and supposed to be used as overlay layer, the JPEG is not a possible choice, and PNG16+transparency is a very interesting tool to reduce size of maps files.

      Anyway, at the end, it's up to each of users to do his own tests, and choose what seems to be the best for him/her

       

      Last edit: Laurent Grenet 2026-07-31
  • Michael Bechtold

    TXs for all your insights, Laurent.

     

Log in to post a comment.