mirror of
https://github.com/willnorris/imageproxy.git
synced 2024-12-16 21:56:43 -05:00
allow forcing encoding as tiff
This commit is contained in:
parent
c1a9dab401
commit
817908938e
3 changed files with 25 additions and 8 deletions
|
@ -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, webp & tiff (decode only), and gif image formats (including animated gifs)
|
- support for jpeg, png, webp (decode only), tiff, 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
|
||||||
|
|
||||||
|
@ -192,7 +192,7 @@ However, you can use the `scaleUp` command-line flag to allow this to happen:
|
||||||
|
|
||||||
imageproxy -scaleUp true
|
imageproxy -scaleUp true
|
||||||
|
|
||||||
### WebP support ###
|
### WebP and TIFF support ###
|
||||||
|
|
||||||
Imageproxy can proxy remote webp images, but they will be served in either jpeg
|
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 supports webp
|
or png format (this is because the golang webp library only supports webp
|
||||||
|
@ -201,6 +201,11 @@ 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
|
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.
|
webp image will be served as-is without any format conversion.
|
||||||
|
|
||||||
|
Because so few browsers support tiff images, they will be converted to jpeg by
|
||||||
|
default if any transformation is requested. To force encoding as tiff, pass the
|
||||||
|
"tiff" option. Like webp, tiff images will be served as-is without any format
|
||||||
|
conversion if no transformation is requested.
|
||||||
|
|
||||||
|
|
||||||
Run `imageproxy -help` for a complete list of flags the command accepts. If
|
Run `imageproxy -help` for a complete list of flags the command accepts. If
|
||||||
you want to use a different caching implementation, it's probably easiest to
|
you want to use a different caching implementation, it's probably easiest to
|
||||||
|
|
9
data.go
9
data.go
|
@ -29,6 +29,7 @@ const (
|
||||||
optFlipHorizontal = "fh"
|
optFlipHorizontal = "fh"
|
||||||
optFormatJPEG = "jpeg"
|
optFormatJPEG = "jpeg"
|
||||||
optFormatPNG = "png"
|
optFormatPNG = "png"
|
||||||
|
optFormatTIFF = "tiff"
|
||||||
optRotatePrefix = "r"
|
optRotatePrefix = "r"
|
||||||
optQualityPrefix = "q"
|
optQualityPrefix = "q"
|
||||||
optSignaturePrefix = "s"
|
optSignaturePrefix = "s"
|
||||||
|
@ -77,7 +78,7 @@ type Options struct {
|
||||||
// will always be overwritten by the value of Proxy.ScaleUp.
|
// will always be overwritten by the value of Proxy.ScaleUp.
|
||||||
ScaleUp bool
|
ScaleUp bool
|
||||||
|
|
||||||
// Desired image format. Valid values are "jpeg", "png".
|
// Desired image format. Valid values are "jpeg", "png", "tiff".
|
||||||
Format string
|
Format string
|
||||||
|
|
||||||
// Crop rectangle params
|
// Crop rectangle params
|
||||||
|
@ -202,8 +203,8 @@ func (o Options) transform() bool {
|
||||||
//
|
//
|
||||||
// Format
|
// Format
|
||||||
//
|
//
|
||||||
// The "jpeg" and "png" options can be used to specify the desired image format
|
// The "jpeg", "png", and "tiff" options can be used to specify the desired
|
||||||
// of the proxied image.
|
// image format of the proxied image.
|
||||||
//
|
//
|
||||||
// Signature
|
// Signature
|
||||||
//
|
//
|
||||||
|
@ -243,7 +244,7 @@ func ParseOptions(str string) Options {
|
||||||
options.FlipHorizontal = true
|
options.FlipHorizontal = true
|
||||||
case opt == optScaleUp: // this option is intentionally not documented above
|
case opt == optScaleUp: // this option is intentionally not documented above
|
||||||
options.ScaleUp = true
|
options.ScaleUp = true
|
||||||
case opt == optFormatJPEG, opt == optFormatPNG:
|
case opt == optFormatJPEG, opt == optFormatPNG, opt == optFormatTIFF:
|
||||||
options.Format = opt
|
options.Format = opt
|
||||||
case strings.HasPrefix(opt, optRotatePrefix):
|
case strings.HasPrefix(opt, optRotatePrefix):
|
||||||
value := strings.TrimPrefix(opt, optRotatePrefix)
|
value := strings.TrimPrefix(opt, optRotatePrefix)
|
||||||
|
|
15
transform.go
15
transform.go
|
@ -24,8 +24,8 @@ import (
|
||||||
"math"
|
"math"
|
||||||
|
|
||||||
"github.com/disintegration/imaging"
|
"github.com/disintegration/imaging"
|
||||||
|
"golang.org/x/image/tiff" // register tiff format
|
||||||
_ "golang.org/x/image/webp" // register webp format
|
_ "golang.org/x/image/webp" // register webp format
|
||||||
_ "golang.org/x/image/tiff" // register tiff format
|
|
||||||
"willnorris.com/go/gifresize"
|
"willnorris.com/go/gifresize"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -50,6 +50,11 @@ func Transform(img []byte, opt Options) ([]byte, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// encode webp and tiff as jpeg by default
|
||||||
|
if format == "tiff" || format == "webp" {
|
||||||
|
format = "jpeg"
|
||||||
|
}
|
||||||
|
|
||||||
if opt.Format != "" {
|
if opt.Format != "" {
|
||||||
format = opt.Format
|
format = opt.Format
|
||||||
}
|
}
|
||||||
|
@ -65,7 +70,7 @@ func Transform(img []byte, opt Options) ([]byte, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
case "jpeg", "webp", "tiff": // default to encoding webp & tiff as jpeg
|
case "jpeg":
|
||||||
quality := opt.Quality
|
quality := opt.Quality
|
||||||
if quality == 0 {
|
if quality == 0 {
|
||||||
quality = defaultQuality
|
quality = defaultQuality
|
||||||
|
@ -82,6 +87,12 @@ func Transform(img []byte, opt Options) ([]byte, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
case "tiff":
|
||||||
|
m = transformImage(m, opt)
|
||||||
|
err = tiff.Encode(buf, m, &tiff.Options{tiff.Deflate, true})
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unsupported format: %v", format)
|
return nil, fmt.Errorf("unsupported format: %v", format)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue