1
0
mirror of https://github.com/imgproxy/imgproxy.git synced 2025-03-17 20:17:48 +02:00

Don't fail if smart crop is not supported but requested

This commit is contained in:
DarthSim 2019-06-11 19:31:18 +06:00
parent 6f889a14da
commit e4b8332752
2 changed files with 13 additions and 7 deletions

View File

@ -8,6 +8,8 @@ import (
"golang.org/x/sync/errgroup"
)
const msgSmartCropNotSupported = "Smart crop is not supported by used version of libvips"
func extractMeta(img *vipsImage) (int, int, int, bool) {
width := img.Width()
height := img.Height()
@ -459,10 +461,6 @@ func processImage(ctx context.Context) ([]byte, context.CancelFunc, error) {
data := getImageData(ctx).Bytes()
imgtype := getImageType(ctx)
if po.Gravity.Type == gravitySmart && !vipsSupportSmartcrop {
return nil, func() {}, errSmartCropNotSupported
}
if po.Format == imageTypeUnknown {
if vipsTypeSupportSave[imgtype] {
po.Format = imgtype
@ -471,6 +469,17 @@ func processImage(ctx context.Context) ([]byte, context.CancelFunc, error) {
}
}
if !vipsSupportSmartcrop {
if po.Gravity.Type == gravitySmart {
logWarning(msgSmartCropNotSupported)
po.Gravity.Type = gravityCenter
}
if po.Crop.Gravity.Type == gravitySmart {
logWarning(msgSmartCropNotSupported)
po.Crop.Gravity.Type = gravityCenter
}
}
if po.Resize == resizeCrop {
logWarning("`crop` resizing type is deprecated and will be removed in future versions. Use `crop` processing option instead")

View File

@ -9,7 +9,6 @@ package main
import "C"
import (
"context"
"errors"
"math"
"os"
"runtime"
@ -27,8 +26,6 @@ var (
vipsTypeSupportSave = make(map[imageType]bool)
watermark *vipsImage
errSmartCropNotSupported = errors.New("Smart crop is not supported by used version of libvips")
)
var vipsConf struct {