mirror of
https://github.com/willnorris/imageproxy.git
synced 2026-05-06 10:32:41 +02: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"
|
||||||
"github.com/muesli/smartcrop/nfnt"
|
"github.com/muesli/smartcrop/nfnt"
|
||||||
"github.com/rwcarlsen/goexif/exif"
|
"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/tiff" // register tiff format
|
||||||
_ "golang.org/x/image/webp" // register webp format
|
_ "golang.org/x/image/webp" // register webp format
|
||||||
"willnorris.com/go/gifresize"
|
"willnorris.com/go/gifresize"
|
||||||
|
|
@ -79,6 +80,12 @@ func Transform(img []byte, opt Options) ([]byte, error) {
|
||||||
// transform and encode image
|
// transform and encode image
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
switch format {
|
switch format {
|
||||||
|
case "bmp":
|
||||||
|
m = transformImage(m, opt)
|
||||||
|
err = bmp.Encode(buf, m)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
case "gif":
|
case "gif":
|
||||||
fn := func(img image.Image) image.Image {
|
fn := func(img image.Image) image.Image {
|
||||||
return transformImage(img, opt)
|
return transformImage(img, opt)
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/disintegration/imaging"
|
"github.com/disintegration/imaging"
|
||||||
|
"golang.org/x/image/bmp"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
@ -111,6 +112,7 @@ func TestTransform(t *testing.T) {
|
||||||
encode func(io.Writer, image.Image)
|
encode func(io.Writer, image.Image)
|
||||||
exactOutput bool // whether input and output should match exactly
|
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},
|
{"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},
|
{"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},
|
{"png", func(w io.Writer, m image.Image) { png.Encode(w, m) }, true},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue