https://github.com/sigoden/dynimgen
A dynamic image generator.
https://github.com/sigoden/dynimgen
dynamic-image-generator image-generator poster-generator rust
Last synced: 8 months ago
JSON representation
A dynamic image generator.
- Host: GitHub
- URL: https://github.com/sigoden/dynimgen
- Owner: sigoden
- License: apache-2.0
- Created: 2022-06-06T13:35:43.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-06-20T07:43:06.000Z (almost 4 years ago)
- Last Synced: 2024-11-27T21:15:52.222Z (over 1 year ago)
- Topics: dynamic-image-generator, image-generator, poster-generator, rust
- Language: Rust
- Homepage:
- Size: 508 KB
- Stars: 30
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# dynimgen
[](https://github.com/sigoden/dynimgen/actions/workflows/ci.yaml)
[](https://crates.io/crates/dynimgen)
A dynamic image generator.

## How to use
step 1: The designers export the design drawing as an svg file
```svg
66666
```
step 2: The engineers edit the svg file, replace the changed parts with template variables
```
{{ code }}
```
step 3: Run `dynimgen`, make sure the svg template is in the `dynimgen` workdir
```sh
$ 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
```
+ + ? +
```
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:
1. Extract path and variables from the request
2. Pass variables to template engine to generate a svg
3. Render the svg to a png then response
## Install
### With cargo
```
cargo install dynimgen
```
### With docker
```
docker run -v `pwd`/data:/data -p 8080:8080 --rm -it sigoden/dynimgen /data
```
### Binaries on macOS, Linux, Windows
Download from [Github Releases](https://github.com/sigoden/dynimgen/releases), unzip and add duf to your $PATH.
## Template Engine
**dynimgen** uses [Tera](https://github.com/Keats/tera) as the template engine. It has a syntax based on [Jinja2](http://jinja.pocoo.org/) and [Django](https://docs.djangoproject.com/en/3.1/topics/templates/) templates.
See the [Tera Documentation](https://tera.netlify.app/docs/#templates) for more information about [control structures](https://tera.netlify.app/docs/#control-structures), [built-ins filters](https://tera.netlify.app/docs/#built-ins), 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') }}`
## License
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.