Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shogo82148/go-imageflux
URL builder for ImageFlux
https://github.com/shogo82148/go-imageflux
golang imageflux url-builder
Last synced: about 2 months ago
JSON representation
URL builder for ImageFlux
- Host: GitHub
- URL: https://github.com/shogo82148/go-imageflux
- Owner: shogo82148
- License: mit
- Created: 2017-09-01T09:57:26.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2024-08-14T07:59:23.000Z (5 months ago)
- Last Synced: 2024-10-14T20:48:51.116Z (3 months ago)
- Topics: golang, imageflux, url-builder
- Language: Go
- Homepage:
- Size: 234 KB
- Stars: 1
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-imageflux
[![Build Status](https://github.com/shogo82148/go-imageflux/workflows/test/badge.svg?branch=main)](https://github.com/shogo82148/go-imageflux/actions)
[![Go Reference](https://pkg.go.dev/badge/github.com/shogo82148/go-imageflux.svg)](https://pkg.go.dev/github.com/shogo82148/go-imageflux)URL builder and parser for [ImageFlux](https://imageflux.sakura.ad.jp/).
## Usage
[ImageFlux](https://imageflux.sakura.ad.jp/) is Image Conversion & Distribution Engine.
This allows you to easily generate images optimized for each device based on a single source image,
and delivers them quickly and with high quality.The imageflux package builds and parse URLs for ImageFlux.
### Build URL
In ImageFlux, parameters for image transformation are embedded in the URL.
```go
proxy := &imageflux.Proxy{
Host: "demo.imageflux.jp",
}
cfg := &imageflux.Config{
// resize the image to 200px width.
Width: 200,// convert the image to WebP format.
Format: imageflux.FormatWebPAuto,
}
u := proxy.Image("/images/1.jpg", cfg).SignedURL()
fmt.Println(u)// Output:
// https://demo.imageflux.jp/c/w=200,f=webp:auto/images/1.jpg
```### Build Signed URL
By attaching a signature to the transformation parameters,
it prevents third parties from rewriting the URL.```go
proxy := &imageflux.Proxy{
Host: "demo.imageflux.jp",
Secret: "testsigningsecret",
}
cfg := &imageflux.Config{
// resize the image to 200px width.
Width: 200,
}
u := proxy.Image("/images/1.jpg", cfg).SignedURL()
fmt.Println(u)// Output:
// https://demo.imageflux.jp/c/sig=1.tiKX5u2kw6wp9zDgl1tLiOIi8IsoRIBw8fVgVc0yrNg=,w=200/images/1.jpg
```### Parse URL
```go
proxy := &imageflux.Proxy{}
image, err := proxy.Parse("/c/w=200/images/1.jpg", "")
if err != nil {
log.Fatal(err)
}
fmt.Printf("path = %s\n", image.Path)
fmt.Printf("width = %d\n", image.Config.Width)// Output:
// path = /images/1.jpg
// width = 200
```## References
- [ImageFlux](https://imageflux.sakura.ad.jp/) (written in Japanese)
- [The document of ImageFlux](https://console.imageflux.jp/docs/) (written in Japanese)