A dynamic image generator.
step 1: The designers export the design drawing as an svg file
<svg>
<rect />
<image src="img.png" />
<image src="qr.png" />
<text>66666</text>
</svg>
step 2: The engineers edit the svg file, replace the changed parts with template variables
<svg>
<rect />
<img src="{{ img | fetch }}">
<img src="{{ qr | to_qr }}">
<text>{{ code }}</text>
</svg>
step 3: Run dynimgen
, make sure the svg template is in the dynimgen
workdir
$ ls data/
Times New Roman.ttf poster1.svg
$ dynimgen data/
[2022-06-05T14:51:53Z INFO dynimgen::generator] Mount `/poster1`
[2022-06-05T14:51:53Z INFO dynimgen] Listen on 0.0.0.0:8080
step 4: Build image url according to the following rules
<domain> + <template path> + ? + <template variables>
For example:
- domain: http://localhost:8080
- template path: /poster1
- template variables: { img: "https://picsum.photos/250", qr: "dynimgen", code: 12345 }
Build url:
http://localhost:8080/poster1?img=https://picsum.photos/250&qr=dynimgen&code=12345
If you request this url, dynimgen will response a png image.
what dynimgen does:
- Extract path and variables from the request
- Pass variables to template engine to generate a svg
- Render the svg to a png then response
cargo install dynimgen
docker run -v `pwd`/data:/data -p 8080:8080 --rm -it sigoden/dynimgen /data
Download from Github Releases, unzip and add duf to your $PATH.
dynimgen uses Tera as the template engine. It has a syntax based on Jinja2 and Django templates.
See the Tera Documentation for more information about control structures, built-ins filters, etc.
Custom built-in filters that dynimgen uses:
Fetch remote resource and encode as data-url
Example: {{ img | fetch }}
{{ img | fetch(timeout=10000) }}
Convert text to qrcode
Example: {{ qr | to_qr }}
{{ qr | to_qr(bg='#fff', fg='#000') }}
Copyright (c) 2022 dynimgen-developers.
dynimgen is made available under the terms of either the MIT License or the Apache License 2.0, at your option.
See the LICENSE-APACHE and LICENSE-MIT files for license details.