mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-09 07:28:44 -07:00
support Palette option for png
This commit is contained in:
parent
3a950d13cd
commit
dfd363a962
4 changed files with 8 additions and 3 deletions
|
|
@ -225,4 +225,5 @@ type Options struct {
|
||||||
Gamma float64
|
Gamma float64
|
||||||
OutputICC string
|
OutputICC string
|
||||||
InputICC string
|
InputICC string
|
||||||
|
Palette bool
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -176,6 +176,7 @@ func saveImage(image *C.VipsImage, o Options) ([]byte, error) {
|
||||||
OutputICC: o.OutputICC,
|
OutputICC: o.OutputICC,
|
||||||
StripMetadata: o.StripMetadata,
|
StripMetadata: o.StripMetadata,
|
||||||
Lossless: o.Lossless,
|
Lossless: o.Lossless,
|
||||||
|
Palette: o.Palette,
|
||||||
}
|
}
|
||||||
// Finally get the resultant buffer
|
// Finally get the resultant buffer
|
||||||
return vipsSave(image, saveOptions)
|
return vipsSave(image, saveOptions)
|
||||||
|
|
|
||||||
4
vips.go
4
vips.go
|
|
@ -55,6 +55,7 @@ type vipsSaveOptions struct {
|
||||||
InputICC string // Absolute path to the input ICC profile
|
InputICC string // Absolute path to the input ICC profile
|
||||||
OutputICC string // Absolute path to the output ICC profile
|
OutputICC string // Absolute path to the output ICC profile
|
||||||
Interpretation Interpretation
|
Interpretation Interpretation
|
||||||
|
Palette bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type vipsWatermarkOptions struct {
|
type vipsWatermarkOptions struct {
|
||||||
|
|
@ -458,6 +459,7 @@ func vipsSave(image *C.VipsImage, o vipsSaveOptions) ([]byte, error) {
|
||||||
quality := C.int(o.Quality)
|
quality := C.int(o.Quality)
|
||||||
strip := C.int(boolToInt(o.StripMetadata))
|
strip := C.int(boolToInt(o.StripMetadata))
|
||||||
lossless := C.int(boolToInt(o.Lossless))
|
lossless := C.int(boolToInt(o.Lossless))
|
||||||
|
palette := C.int(boolToInt(o.Palette))
|
||||||
|
|
||||||
if o.Type != 0 && !IsTypeSupportedSave(o.Type) {
|
if o.Type != 0 && !IsTypeSupportedSave(o.Type) {
|
||||||
return nil, fmt.Errorf("VIPS cannot save to %#v", ImageTypes[o.Type])
|
return nil, fmt.Errorf("VIPS cannot save to %#v", ImageTypes[o.Type])
|
||||||
|
|
@ -467,7 +469,7 @@ func vipsSave(image *C.VipsImage, o vipsSaveOptions) ([]byte, error) {
|
||||||
case WEBP:
|
case WEBP:
|
||||||
saveErr = C.vips_webpsave_bridge(tmpImage, &ptr, &length, strip, quality, lossless)
|
saveErr = C.vips_webpsave_bridge(tmpImage, &ptr, &length, strip, quality, lossless)
|
||||||
case PNG:
|
case PNG:
|
||||||
saveErr = C.vips_pngsave_bridge(tmpImage, &ptr, &length, strip, C.int(o.Compression), quality, interlace)
|
saveErr = C.vips_pngsave_bridge(tmpImage, &ptr, &length, strip, C.int(o.Compression), quality, interlace, palette)
|
||||||
case TIFF:
|
case TIFF:
|
||||||
saveErr = C.vips_tiffsave_bridge(tmpImage, &ptr, &length)
|
saveErr = C.vips_tiffsave_bridge(tmpImage, &ptr, &length)
|
||||||
case HEIF:
|
case HEIF:
|
||||||
|
|
|
||||||
5
vips.h
5
vips.h
|
|
@ -309,13 +309,14 @@ vips_jpegsave_bridge(VipsImage *in, void **buf, size_t *len, int strip, int qual
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
vips_pngsave_bridge(VipsImage *in, void **buf, size_t *len, int strip, int compression, int quality, int interlace) {
|
vips_pngsave_bridge(VipsImage *in, void **buf, size_t *len, int strip, int compression, int quality, int interlace, int palette) {
|
||||||
#if (VIPS_MAJOR_VERSION >= 8 || (VIPS_MAJOR_VERSION >= 7 && VIPS_MINOR_VERSION >= 42))
|
#if (VIPS_MAJOR_VERSION >= 8 && VIPS_MINOR_VERSION >= 7)
|
||||||
return vips_pngsave_buffer(in, buf, len,
|
return vips_pngsave_buffer(in, buf, len,
|
||||||
"strip", INT_TO_GBOOLEAN(strip),
|
"strip", INT_TO_GBOOLEAN(strip),
|
||||||
"compression", compression,
|
"compression", compression,
|
||||||
"interlace", INT_TO_GBOOLEAN(interlace),
|
"interlace", INT_TO_GBOOLEAN(interlace),
|
||||||
"filter", VIPS_FOREIGN_PNG_FILTER_ALL,
|
"filter", VIPS_FOREIGN_PNG_FILTER_ALL,
|
||||||
|
"palette", INT_TO_GBOOLEAN(palette),
|
||||||
NULL
|
NULL
|
||||||
);
|
);
|
||||||
#else
|
#else
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue