mirror of
https://github.com/willnorris/imageproxy.git
synced 2026-05-10 20:42:40 +02:00
add support for specifying output image format
For now, the options are "jpeg" and "png". Gif is a little harder to support because of the way we use the image/gif package to handle animated gifs. I have also have trouble imagining someone wanting to use gif over png. But if the need really exists, we can address it when it comes up. Fixes #89
This commit is contained in:
parent
2937bf84f6
commit
b9cc9df4b6
4 changed files with 37 additions and 8 deletions
|
|
@ -16,6 +16,7 @@ package imageproxy
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"image"
|
||||
_ "image/gif" // register gif format
|
||||
"image/jpeg"
|
||||
|
|
@ -46,6 +47,10 @@ func Transform(img []byte, opt Options) ([]byte, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
if opt.Format != "" {
|
||||
format = opt.Format
|
||||
}
|
||||
|
||||
// transform and encode image
|
||||
buf := new(bytes.Buffer)
|
||||
switch format {
|
||||
|
|
@ -74,6 +79,8 @@ func Transform(img []byte, opt Options) ([]byte, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported format: %v", format)
|
||||
}
|
||||
|
||||
return buf.Bytes(), nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue