From 1547c623a9028c43492a30f38fecdf954bb36993 Mon Sep 17 00:00:00 2001 From: igsr5 Date: Thu, 24 Mar 2022 15:19:43 +0900 Subject: [PATCH 1/2] Add getter, setter for MaxSize --- options.go | 26 +++++++++++++++++++++++--- vips.go | 4 ++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/options.go b/options.go index 93a40bd..39370a1 100644 --- a/options.go +++ b/options.go @@ -5,14 +5,34 @@ package bimg #include "vips/vips.h" */ import "C" +import "fmt" const ( // Quality defines the default JPEG quality to be used. Quality = 75 - // MaxSize defines the maximum pixels width or height supported. - MaxSize = 16383 + // maxSize defines the maximum pixels width or height supported. ) +var maxSize = 16383 + +// MaxSize returns maxSize. +// maxSize defines maximum pixels width or height supported. +func MaxSize() int { + return maxSize +} + +// SetMaxSize sets maxSize. +// maxSize defines maximum pixels width or height supported. +func SetMaxsize(s int) error { + if s <= 0 { + return fmt.Errorf("invalid size.A size must be 0.") + } + + maxSize = s + + return nil +} + // Gravity represents the image gravity value. type Gravity int @@ -226,7 +246,7 @@ type Options struct { OutputICC string InputICC string Palette bool - // Speed defines the AVIF encoders CPU effort. Valid values are: + // Speed defines the AVIF encoders CPU effort. Valid values are: // 0-8 for AVIF encoding. // 0-9 for PNG encoding. Speed int diff --git a/vips.go b/vips.go index 5b8067a..dbad3aa 100644 --- a/vips.go +++ b/vips.go @@ -564,7 +564,7 @@ func vipsExtract(image *C.VipsImage, left, top, width, height int) (*C.VipsImage var buf *C.VipsImage defer C.g_object_unref(C.gpointer(image)) - if width > MaxSize || height > MaxSize { + if width > MaxSize() || height > MaxSize() { return nil, errors.New("Maximum image size exceeded") } @@ -581,7 +581,7 @@ func vipsSmartCrop(image *C.VipsImage, width, height int) (*C.VipsImage, error) var buf *C.VipsImage defer C.g_object_unref(C.gpointer(image)) - if width > MaxSize || height > MaxSize { + if width > MaxSize() || height > MaxSize() { return nil, errors.New("Maximum image size exceeded") } From 03d98b00ba71059ca059bacc14428cda168ea85d Mon Sep 17 00:00:00 2001 From: igsr5 Date: Tue, 5 Apr 2022 21:40:08 +0900 Subject: [PATCH 2/2] Fix review --- options.go | 8 +++----- vips.go | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/options.go b/options.go index 39370a1..e4c88ae 100644 --- a/options.go +++ b/options.go @@ -5,27 +5,25 @@ package bimg #include "vips/vips.h" */ import "C" -import "fmt" +import "errors" const ( // Quality defines the default JPEG quality to be used. Quality = 75 - // maxSize defines the maximum pixels width or height supported. ) +// maxSize defines maximum pixels width or height supported. var maxSize = 16383 // MaxSize returns maxSize. -// maxSize defines maximum pixels width or height supported. func MaxSize() int { return maxSize } // SetMaxSize sets maxSize. -// maxSize defines maximum pixels width or height supported. func SetMaxsize(s int) error { if s <= 0 { - return fmt.Errorf("invalid size.A size must be 0.") + return errors.New("Size must be higher than zero.") } maxSize = s diff --git a/vips.go b/vips.go index dbad3aa..d827257 100644 --- a/vips.go +++ b/vips.go @@ -564,7 +564,7 @@ func vipsExtract(image *C.VipsImage, left, top, width, height int) (*C.VipsImage var buf *C.VipsImage defer C.g_object_unref(C.gpointer(image)) - if width > MaxSize() || height > MaxSize() { + if width > maxSize || height > maxSize { return nil, errors.New("Maximum image size exceeded") } @@ -581,7 +581,7 @@ func vipsSmartCrop(image *C.VipsImage, width, height int) (*C.VipsImage, error) var buf *C.VipsImage defer C.g_object_unref(C.gpointer(image)) - if width > MaxSize() || height > MaxSize() { + if width > maxSize || height > maxSize { return nil, errors.New("Maximum image size exceeded") }