|
|
|
@ -32,6 +32,14 @@ func Resize(buf []byte, o Options) ([]byte, error) {
|
|
|
|
|
|
|
|
|
|
|
|
debug("Options: %#v", o)
|
|
|
|
debug("Options: %#v", o)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Initial image auto rotate / flip for proper transformation calculus
|
|
|
|
|
|
|
|
if o.Rotate == 0 {
|
|
|
|
|
|
|
|
image, err = rotateAndFlipImage(image, o)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
inWidth := int(image.Xsize)
|
|
|
|
inWidth := int(image.Xsize)
|
|
|
|
inHeight := int(image.Ysize)
|
|
|
|
inHeight := int(image.Ysize)
|
|
|
|
|
|
|
|
|
|
|
|
@ -74,12 +82,6 @@ func Resize(buf []byte, o Options) ([]byte, error) {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Rotate / flip image, if necessary
|
|
|
|
|
|
|
|
image, err = rotateAndFlipImage(image, o)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Transform image, if necessary
|
|
|
|
// Transform image, if necessary
|
|
|
|
if shouldTransformImage(o, inWidth, inHeight) {
|
|
|
|
if shouldTransformImage(o, inWidth, inHeight) {
|
|
|
|
image, err = transformImage(image, o, shrink, residual)
|
|
|
|
image, err = transformImage(image, o, shrink, residual)
|
|
|
|
@ -102,6 +104,12 @@ func Resize(buf []byte, o Options) ([]byte, error) {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Transform to original rotation, if necessary
|
|
|
|
|
|
|
|
image, err = rotateAndFlipImage(image, o)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Flatten image on a background, if necessary
|
|
|
|
// Flatten image on a background, if necessary
|
|
|
|
image, err = imageFlatten(image, imageType, o)
|
|
|
|
image, err = imageFlatten(image, imageType, o)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
@ -149,7 +157,7 @@ func shouldTransformImage(o Options, inWidth, inHeight int) bool {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func shouldApplyEffects(o Options) bool {
|
|
|
|
func shouldApplyEffects(o Options) bool {
|
|
|
|
return o.GaussianBlur.Sigma > 0 || o.GaussianBlur.MinAmpl > 0 || o.Sharpen.Radius > 0 && o.Sharpen.Y2 > 0 || o.Sharpen.Y3 > 0
|
|
|
|
return o.GaussianBlur.Sigma > 0 || o.GaussianBlur.MinAmpl > 0 || o.Sharpen.Radius > 0 && o.Sharpen.Y2 > 0 || o.Sharpen.Y3 > 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func transformImage(image *C.VipsImage, o Options, shrink int, residual float64) (*C.VipsImage, error) {
|
|
|
|
func transformImage(image *C.VipsImage, o Options, shrink int, residual float64) (*C.VipsImage, error) {
|
|
|
|
|