Skip to content
/ komorebi Public

Middleware that dynamically resizes image to (almost) a specified width/height.

License

Notifications You must be signed in to change notification settings

wlmac/komorebi

Repository files navigation

Komorebi

Middleware that dynamically resizes image to (almost) a specified width/height.

On the Metropolis website, static media was directly served from the uploaded version, which were usually unnecessarily larger and were not in a optimal format (e.g. PNG).

In order to speed up loading times, I developed this to transparently1 reduce bandwidth used. A quick search did not turn up a simple reverse proxy that I could put transparently (i.e. disables itself if not explicitly used) and has the least amount of features I need. (Actually, Patrick found https://github.com/cshum/imagor , which is a more complex version of this… Literature surveys are important!)

To run, compile cmd/proxy and run it with -net and -addr to specify the network and address (e.g. -net unix -addr /run/komorebi.sock).

API

/<path>?w=&h=&fmt=

where <path> is the source path of the file w is the width (0 to leave blank) h is the height (0 to leave blank) fmt is the format (only webp is supported)

Example

TODO

  • clamp width and height of the resultant image
  • store metrics and clear cache from most unused
  • more formats (JPEG, PNG, AVIF)

Footnotes

  1. We only reverse proxy to Komorebi when there is a width=[0-9]+px request query parameter.

About

Middleware that dynamically resizes image to (almost) a specified width/height.

Resources

License

Stars

Watchers

Forks

Packages

No packages published