mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-09 07:28:44 -07:00
feat: support multiple outputs
This commit is contained in:
parent
d471c49348
commit
ef10d7d7ec
9 changed files with 220 additions and 58 deletions
21
resize.go
21
resize.go
|
|
@ -7,6 +7,7 @@ package bimg
|
|||
import "C"
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"math"
|
||||
)
|
||||
|
||||
|
|
@ -27,7 +28,7 @@ const (
|
|||
func Resize(buf []byte, o Options) ([]byte, error) {
|
||||
defer C.vips_thread_shutdown()
|
||||
|
||||
image, err := vipsRead(buf)
|
||||
image, imageType, err := vipsRead(buf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -36,6 +37,12 @@ func Resize(buf []byte, o Options) ([]byte, error) {
|
|||
if o.Quality == 0 {
|
||||
o.Quality = QUALITY
|
||||
}
|
||||
if o.Compression == 0 {
|
||||
o.Compression = 6
|
||||
}
|
||||
if o.Type == 0 {
|
||||
o.Type = imageType
|
||||
}
|
||||
|
||||
// get WxH
|
||||
inWidth := int(image.Xsize)
|
||||
|
|
@ -74,7 +81,17 @@ func Resize(buf []byte, o Options) ([]byte, error) {
|
|||
}
|
||||
}
|
||||
|
||||
buf, err = vipsSave(image, vipsSaveOptions{Quality: o.Quality})
|
||||
if IsTypeSupported(o.Type) == false {
|
||||
return nil, errors.New("Unsupported image output type")
|
||||
}
|
||||
|
||||
saveOptions := vipsSaveOptions{
|
||||
Quality: o.Quality,
|
||||
Type: o.Type,
|
||||
Compression: o.Compression,
|
||||
}
|
||||
|
||||
buf, err = vipsSave(image, saveOptions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue