mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-15 18:35:54 -07:00
Merge pull request #208 from mikestead/feature/webp-lossless
Add lossless option for saving webp
This commit is contained in:
commit
262d0f82b7
4 changed files with 7 additions and 2 deletions
|
|
@ -209,6 +209,7 @@ type Options struct {
|
||||||
Interlace bool
|
Interlace bool
|
||||||
StripMetadata bool
|
StripMetadata bool
|
||||||
Trim bool
|
Trim bool
|
||||||
|
Lossless bool
|
||||||
Extend Extend
|
Extend Extend
|
||||||
Rotate Angle
|
Rotate Angle
|
||||||
Background Color
|
Background Color
|
||||||
|
|
|
||||||
|
|
@ -165,6 +165,7 @@ func saveImage(image *C.VipsImage, o Options) ([]byte, error) {
|
||||||
Interpretation: o.Interpretation,
|
Interpretation: o.Interpretation,
|
||||||
OutputICC: o.OutputICC,
|
OutputICC: o.OutputICC,
|
||||||
StripMetadata: o.StripMetadata,
|
StripMetadata: o.StripMetadata,
|
||||||
|
Lossless: o.Lossless,
|
||||||
}
|
}
|
||||||
// Finally get the resultant buffer
|
// Finally get the resultant buffer
|
||||||
return vipsSave(image, saveOptions)
|
return vipsSave(image, saveOptions)
|
||||||
|
|
|
||||||
4
vips.go
4
vips.go
|
|
@ -56,6 +56,7 @@ type vipsSaveOptions struct {
|
||||||
Interlace bool
|
Interlace bool
|
||||||
NoProfile bool
|
NoProfile bool
|
||||||
StripMetadata bool
|
StripMetadata bool
|
||||||
|
Lossless bool
|
||||||
OutputICC string // Absolute path to the output ICC profile
|
OutputICC string // Absolute path to the output ICC profile
|
||||||
Interpretation Interpretation
|
Interpretation Interpretation
|
||||||
}
|
}
|
||||||
|
|
@ -423,6 +424,7 @@ func vipsSave(image *C.VipsImage, o vipsSaveOptions) ([]byte, error) {
|
||||||
interlace := C.int(boolToInt(o.Interlace))
|
interlace := C.int(boolToInt(o.Interlace))
|
||||||
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))
|
||||||
|
|
||||||
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])
|
||||||
|
|
@ -430,7 +432,7 @@ func vipsSave(image *C.VipsImage, o vipsSaveOptions) ([]byte, error) {
|
||||||
var ptr unsafe.Pointer
|
var ptr unsafe.Pointer
|
||||||
switch o.Type {
|
switch o.Type {
|
||||||
case WEBP:
|
case WEBP:
|
||||||
saveErr = C.vips_webpsave_bridge(tmpImage, &ptr, &length, strip, quality)
|
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)
|
||||||
case TIFF:
|
case TIFF:
|
||||||
|
|
|
||||||
3
vips.h
3
vips.h
|
|
@ -306,10 +306,11 @@ vips_pngsave_bridge(VipsImage *in, void **buf, size_t *len, int strip, int compr
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
vips_webpsave_bridge(VipsImage *in, void **buf, size_t *len, int strip, int quality) {
|
vips_webpsave_bridge(VipsImage *in, void **buf, size_t *len, int strip, int quality, int lossless) {
|
||||||
return vips_webpsave_buffer(in, buf, len,
|
return vips_webpsave_buffer(in, buf, len,
|
||||||
"strip", INT_TO_GBOOLEAN(strip),
|
"strip", INT_TO_GBOOLEAN(strip),
|
||||||
"Q", quality,
|
"Q", quality,
|
||||||
|
"lossless", INT_TO_GBOOLEAN(lossless),
|
||||||
NULL
|
NULL
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue