mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-16 02:45:54 -07:00
Add getter, setter for MaxSize
This commit is contained in:
parent
96a6384797
commit
1547c623a9
2 changed files with 25 additions and 5 deletions
26
options.go
26
options.go
|
|
@ -5,14 +5,34 @@ package bimg
|
||||||
#include "vips/vips.h"
|
#include "vips/vips.h"
|
||||||
*/
|
*/
|
||||||
import "C"
|
import "C"
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// Quality defines the default JPEG quality to be used.
|
// Quality defines the default JPEG quality to be used.
|
||||||
Quality = 75
|
Quality = 75
|
||||||
// MaxSize defines the maximum pixels width or height supported.
|
// maxSize defines the maximum pixels width or height supported.
|
||||||
MaxSize = 16383
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
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.
|
// Gravity represents the image gravity value.
|
||||||
type Gravity int
|
type Gravity int
|
||||||
|
|
||||||
|
|
@ -226,7 +246,7 @@ type Options struct {
|
||||||
OutputICC string
|
OutputICC string
|
||||||
InputICC string
|
InputICC string
|
||||||
Palette bool
|
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-8 for AVIF encoding.
|
||||||
// 0-9 for PNG encoding.
|
// 0-9 for PNG encoding.
|
||||||
Speed int
|
Speed int
|
||||||
|
|
|
||||||
4
vips.go
4
vips.go
|
|
@ -564,7 +564,7 @@ func vipsExtract(image *C.VipsImage, left, top, width, height int) (*C.VipsImage
|
||||||
var buf *C.VipsImage
|
var buf *C.VipsImage
|
||||||
defer C.g_object_unref(C.gpointer(image))
|
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")
|
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
|
var buf *C.VipsImage
|
||||||
defer C.g_object_unref(C.gpointer(image))
|
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")
|
return nil, errors.New("Maximum image size exceeded")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue