mirror of
https://github.com/willnorris/imageproxy.git
synced 2024-12-16 21:56:43 -05:00
add support for bmp images
handle decoding and encoding bmp images with transformations. Because this isn't a popular file format, we don't actually expose it as an option for format transformation. Fixes #182
This commit is contained in:
parent
1569bfda30
commit
d4ba5205ff
2 changed files with 9 additions and 0 deletions
|
@ -29,6 +29,7 @@ import (
|
|||
"github.com/muesli/smartcrop"
|
||||
"github.com/muesli/smartcrop/nfnt"
|
||||
"github.com/rwcarlsen/goexif/exif"
|
||||
"golang.org/x/image/bmp" // register bmp format
|
||||
"golang.org/x/image/tiff" // register tiff format
|
||||
_ "golang.org/x/image/webp" // register webp format
|
||||
"willnorris.com/go/gifresize"
|
||||
|
@ -79,6 +80,12 @@ func Transform(img []byte, opt Options) ([]byte, error) {
|
|||
// transform and encode image
|
||||
buf := new(bytes.Buffer)
|
||||
switch format {
|
||||
case "bmp":
|
||||
m = transformImage(m, opt)
|
||||
err = bmp.Encode(buf, m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
case "gif":
|
||||
fn := func(img image.Image) image.Image {
|
||||
return transformImage(img, opt)
|
||||
|
|
|
@ -28,6 +28,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/disintegration/imaging"
|
||||
"golang.org/x/image/bmp"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -111,6 +112,7 @@ func TestTransform(t *testing.T) {
|
|||
encode func(io.Writer, image.Image)
|
||||
exactOutput bool // whether input and output should match exactly
|
||||
}{
|
||||
{"bmp", func(w io.Writer, m image.Image) { bmp.Encode(w, m) }, true},
|
||||
{"gif", func(w io.Writer, m image.Image) { gif.Encode(w, m, nil) }, true},
|
||||
{"jpeg", func(w io.Writer, m image.Image) { jpeg.Encode(w, m, nil) }, false},
|
||||
{"png", func(w io.Writer, m image.Image) { png.Encode(w, m) }, true},
|
||||
|
|
Loading…
Reference in a new issue