mirror of
https://github.com/willnorris/imageproxy.git
synced 2024-12-16 21:56:43 -05:00
simplify transform function to only pass bytes
This commit is contained in:
parent
b4fae2dd5f
commit
b109a87ece
2 changed files with 6 additions and 6 deletions
|
@ -142,7 +142,8 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
image, _ = transform.Transform(*image, req.Options)
|
b, _ := transform.Transform(image.Bytes, req.Options)
|
||||||
|
image.Bytes = b
|
||||||
|
|
||||||
w.Header().Add("Content-Length", strconv.Itoa(len(image.Bytes)))
|
w.Header().Add("Content-Length", strconv.Itoa(len(image.Bytes)))
|
||||||
w.Header().Add("Expires", image.Expires.Format(time.RFC1123))
|
w.Header().Add("Expires", image.Expires.Format(time.RFC1123))
|
||||||
|
|
|
@ -30,14 +30,14 @@ import (
|
||||||
var emptyOptions = new(data.Options)
|
var emptyOptions = new(data.Options)
|
||||||
|
|
||||||
// Transform the provided image.
|
// Transform the provided image.
|
||||||
func Transform(img data.Image, opt *data.Options) (*data.Image, error) {
|
func Transform(img []byte, opt *data.Options) ([]byte, error) {
|
||||||
if opt == nil || reflect.DeepEqual(opt, emptyOptions) {
|
if opt == nil || reflect.DeepEqual(opt, emptyOptions) {
|
||||||
// bail if no transformation was requested
|
// bail if no transformation was requested
|
||||||
return &img, nil
|
return img, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// decode image
|
// decode image
|
||||||
m, format, err := image.Decode(bytes.NewReader(img.Bytes))
|
m, format, err := image.Decode(bytes.NewReader(img))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -103,6 +103,5 @@ func Transform(img data.Image, opt *data.Options) (*data.Image, error) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
img.Bytes = buf.Bytes()
|
return buf.Bytes(), nil
|
||||||
return &img, nil
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue