mirror of
https://github.com/willnorris/imageproxy.git
synced 2026-05-17 07:45:13 +02:00
add webp support (decode only)
if any transformation is requested, webp images will be encoded and served as jpeg or png, defaulting to jpeg if no format is specified. Fixes #88
This commit is contained in:
parent
b9cc9df4b6
commit
328044540e
3 changed files with 14 additions and 3 deletions
11
README.md
11
README.md
|
|
@ -4,7 +4,7 @@ imageproxy is a caching image proxy server written in go. It features:
|
||||||
|
|
||||||
- basic image adjustments like resizing, cropping, and rotation
|
- basic image adjustments like resizing, cropping, and rotation
|
||||||
- access control using host whitelists or request signing (HMAC-SHA256)
|
- access control using host whitelists or request signing (HMAC-SHA256)
|
||||||
- support for jpeg, png, and gif image formats (including animated gifs)
|
- support for jpeg, png, webp (decode only), and gif image formats (including animated gifs)
|
||||||
- on-disk caching, respecting the cache headers of the original images
|
- on-disk caching, respecting the cache headers of the original images
|
||||||
- easy deployment, since it's pure go
|
- easy deployment, since it's pure go
|
||||||
|
|
||||||
|
|
@ -197,6 +197,15 @@ However, you can use the `scaleUp` command-line flag to allow this to happen:
|
||||||
|
|
||||||
imageproxy -scaleUp true
|
imageproxy -scaleUp true
|
||||||
|
|
||||||
|
### WebP support ###
|
||||||
|
|
||||||
|
Imageproxy can proxy remote webp images, but they will be served in either jpeg
|
||||||
|
or png format (this is because the golang webp library only support decoding)
|
||||||
|
if any transformation is requested. If no format is specified, imageproxy will
|
||||||
|
use jpeg by default. If no transformation is requested (for example, if you
|
||||||
|
are just using imageproxy as an SSL proxy) then the original webp image will be
|
||||||
|
served as-is without any format conversion.
|
||||||
|
|
||||||
## Deploying ##
|
## Deploying ##
|
||||||
|
|
||||||
You can build and deploy imageproxy using any standard go toolchain, but here's
|
You can build and deploy imageproxy using any standard go toolchain, but here's
|
||||||
|
|
|
||||||
|
|
@ -308,7 +308,8 @@ func (t *TransformingTransport) RoundTrip(req *http.Request) (*http.Response, er
|
||||||
fmt.Fprintf(buf, "%s %s\n", resp.Proto, resp.Status)
|
fmt.Fprintf(buf, "%s %s\n", resp.Proto, resp.Status)
|
||||||
resp.Header.WriteSubset(buf, map[string]bool{
|
resp.Header.WriteSubset(buf, map[string]bool{
|
||||||
"Content-Length": true,
|
"Content-Length": true,
|
||||||
"Content-Type": opt.Format != "",
|
// exclude Content-Type header if the format may have changed during transformation
|
||||||
|
"Content-Type": opt.Format != "" || resp.Header.Get("Content-Type") == "image/webp",
|
||||||
})
|
})
|
||||||
fmt.Fprintf(buf, "Content-Length: %d\n\n", len(img))
|
fmt.Fprintf(buf, "Content-Length: %d\n\n", len(img))
|
||||||
buf.Write(img)
|
buf.Write(img)
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ import (
|
||||||
"image/png"
|
"image/png"
|
||||||
|
|
||||||
"github.com/disintegration/imaging"
|
"github.com/disintegration/imaging"
|
||||||
|
_ "golang.org/x/image/webp" // register webp format
|
||||||
"willnorris.com/go/gifresize"
|
"willnorris.com/go/gifresize"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -62,7 +63,7 @@ func Transform(img []byte, opt Options) ([]byte, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
case "jpeg":
|
case "jpeg", "webp": // default to encoding webp as jpeg
|
||||||
quality := opt.Quality
|
quality := opt.Quality
|
||||||
if quality == 0 {
|
if quality == 0 {
|
||||||
quality = defaultQuality
|
quality = defaultQuality
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue