From e4b83327525ca3d949cd6bee270bb28e37f47fef Mon Sep 17 00:00:00 2001 From: DarthSim Date: Tue, 11 Jun 2019 19:31:18 +0600 Subject: [PATCH] Don't fail if smart crop is not supported but requested --- process.go | 17 +++++++++++++---- vips.go | 3 --- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/process.go b/process.go index f23c4218..d096bc6f 100644 --- a/process.go +++ b/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") diff --git a/vips.go b/vips.go index f3082f56..2a2472c3 100644 --- a/vips.go +++ b/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 {