diff --git a/README.md b/README.md index 3767412..8e3d1ae 100644 --- a/README.md +++ b/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 - 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 - 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 +### 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 ## You can build and deploy imageproxy using any standard go toolchain, but here's diff --git a/imageproxy.go b/imageproxy.go index 5c0db49..fee43cd 100644 --- a/imageproxy.go +++ b/imageproxy.go @@ -308,7 +308,8 @@ func (t *TransformingTransport) RoundTrip(req *http.Request) (*http.Response, er fmt.Fprintf(buf, "%s %s\n", resp.Proto, resp.Status) resp.Header.WriteSubset(buf, map[string]bool{ "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)) buf.Write(img) diff --git a/transform.go b/transform.go index 4c91913..d550909 100644 --- a/transform.go +++ b/transform.go @@ -23,6 +23,7 @@ import ( "image/png" "github.com/disintegration/imaging" + _ "golang.org/x/image/webp" // register webp format "willnorris.com/go/gifresize" ) @@ -62,7 +63,7 @@ func Transform(img []byte, opt Options) ([]byte, error) { if err != nil { return nil, err } - case "jpeg": + case "jpeg", "webp": // default to encoding webp as jpeg quality := opt.Quality if quality == 0 { quality = defaultQuality