فهرست منبع

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

DarthSim 5 سال پیش
والد
کامیت
e4b8332752
2فایلهای تغییر یافته به همراه13 افزوده شده و 7 حذف شده
  1. 13 4
      process.go
  2. 0 3
      vips.go

+ 13 - 4
process.go

@@ -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")
 

+ 0 - 3
vips.go

@@ -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 {