Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimise images #1

Open
grischard opened this issue Aug 14, 2018 · 6 comments
Open

Optimise images #1

grischard opened this issue Aug 14, 2018 · 6 comments

Comments

@grischard
Copy link

Recompressing images losslessly once would save disk space and bandwidth. I saw about 30% improvement on jpeg sizes on my tile proxy after running mozjpeg.

I'm a fan of ImageOptim for macOS, but alternatives exist for other OSs.

@jochenklar
Copy link
Member

Cool, thanks for the info. However I need to convert the files using gdal first. How do I combine mozjpeg? Any clue? The conversion is here: https://github.com/jochenklar/fis-broker/blob/master/2017/bin/convert.sh

@jochenklar
Copy link
Member

Sorry, that did not make sense, the images are stroed as TIFF on the server, compression needs to happen with tilestache.

@grischard
Copy link
Author

Ah! In that case, since the tiles are generated on the fly, piping them through mozjpeg would add more time than transmission would save. It's interesting that it's still significantly faster than the original wms.

@grischard
Copy link
Author

grischard commented Sep 6, 2018

Reading the tilestache documentation right now for geotiffs in Luxembourg, I see that it can cache rendered tiles, forever by default. Something like this could work with a tilestache.caches.disk:

#!/usr/bin/env python

"""
Optimise JPEGs in a tilestache cache with mozjpeg.

Remembers processed files so they are only processed once.

Find -mtime wouldn't work because optimising the files changes the mtime.
"""

import os
from subprocess import call

PATH = "/home/openstreetmap/tilestache/cache"
MOZJPEG = "/usr/local/bin/mozjpeg"

PROCESSED_FILES_FILE = os.path.join(PATH, "mozjpeg_optimised_tiles.txt")
PROCESSED_FILES = set(line.strip() for line in open(PROCESSED_FILES_FILE))

CACHE_DATA = os.path.join(PATH, "cache_data")

with open(PROCESSED_FILES_FILE, "a") as pff:
    for root, dirs, files in os.walk(CACHE_DATA):
        for tilefile in files:
            if tilefile.endswith(".jpeg"):
                tilepath = os.path.join(root, tilefile)
                if tilepath not in PROCESSED_FILES:
                    call([MOZJPEG,
                          "-copy", "none",
                          "-outfile", tilepath,
                          tilepath])
                    pff.write("%s\n" % tilepath)

@grischard grischard reopened this Sep 6, 2018
@tordans
Copy link
Contributor

tordans commented Feb 11, 2021

@jochenklar do you think we could run this manually on the temp-folders that hold the png-files?
My understand is, that those only get deleted by a manual reset, so running it manually once would be fine. (Otherwise we could maybe run it once a week…)

I see good file size reduction on the new 2020 images as well:

image

For https://tiles.codefor.de/berlin-2020-truedop/18/140918/86125.png, using https://imageoptim.com/mac (https://github.com/ImageOptim/ImageOptim)

Since those images are used mobile as well, saving some bites add up.


@grischard the code you have above is for jpeg, right? As far as I see the cached files are saved as png. Do you have a recommendation on how to optimize those?


Btw, just for reference, ideally this issue would be moved over to https://github.com/codeforberlin/tilestache-config which is the repo that hold the tile-server-config and -code. This one is just a list of all available "layer".

@grischard
Copy link
Author

grischard commented Feb 13, 2021

For png I recommend pngwolf-zopfli. But why would you cache orthoimagery as png?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants