Crates.io | dynimgen |
lib.rs | dynimgen |
version | 0.2.0 |
source | src |
created_at | 2022-06-06 15:17:16.718434 |
updated_at | 2022-06-07 04:37:05.79523 |
description | A self-hosted dynamic image generator. |
homepage | https://github.com/sigoden/dynimgen |
repository | https://github.com/sigoden/dynimgen |
max_upload_size | |
id | 600784 |
size | 68,624 |
A self-hosted 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
poster1.svg
$ dynimgen fixtures/
[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:
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:
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
Fetch remote resource and encode as data-url
Example: {{ img | fetch }}
{{ img | fetch(timeout=10000) }}
to_qr
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.