Skip to content

Commit 262d0f8

Browse files
authored
Merge pull request #208 from mikestead/feature/webp-lossless
Add lossless option for saving webp
2 parents 46db36e + ce5ae9c commit 262d0f8

File tree

4 files changed

+7
-2
lines changed

4 files changed

+7
-2
lines changed

options.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ type Options struct {
209209
Interlace bool
210210
StripMetadata bool
211211
Trim bool
212+
Lossless bool
212213
Extend Extend
213214
Rotate Angle
214215
Background Color

resizer.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ func saveImage(image *C.VipsImage, o Options) ([]byte, error) {
165165
Interpretation: o.Interpretation,
166166
OutputICC: o.OutputICC,
167167
StripMetadata: o.StripMetadata,
168+
Lossless: o.Lossless,
168169
}
169170
// Finally get the resultant buffer
170171
return vipsSave(image, saveOptions)

vips.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ type vipsSaveOptions struct {
5656
Interlace bool
5757
NoProfile bool
5858
StripMetadata bool
59+
Lossless bool
5960
OutputICC string // Absolute path to the output ICC profile
6061
Interpretation Interpretation
6162
}
@@ -423,14 +424,15 @@ func vipsSave(image *C.VipsImage, o vipsSaveOptions) ([]byte, error) {
423424
interlace := C.int(boolToInt(o.Interlace))
424425
quality := C.int(o.Quality)
425426
strip := C.int(boolToInt(o.StripMetadata))
427+
lossless := C.int(boolToInt(o.Lossless))
426428

427429
if o.Type != 0 && !IsTypeSupportedSave(o.Type) {
428430
return nil, fmt.Errorf("VIPS cannot save to %#v", ImageTypes[o.Type])
429431
}
430432
var ptr unsafe.Pointer
431433
switch o.Type {
432434
case WEBP:
433-
saveErr = C.vips_webpsave_bridge(tmpImage, &ptr, &length, strip, quality)
435+
saveErr = C.vips_webpsave_bridge(tmpImage, &ptr, &length, strip, quality, lossless)
434436
case PNG:
435437
saveErr = C.vips_pngsave_bridge(tmpImage, &ptr, &length, strip, C.int(o.Compression), quality, interlace)
436438
case TIFF:

vips.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,11 @@ vips_pngsave_bridge(VipsImage *in, void **buf, size_t *len, int strip, int compr
306306
}
307307

308308
int
309-
vips_webpsave_bridge(VipsImage *in, void **buf, size_t *len, int strip, int quality) {
309+
vips_webpsave_bridge(VipsImage *in, void **buf, size_t *len, int strip, int quality, int lossless) {
310310
return vips_webpsave_buffer(in, buf, len,
311311
"strip", INT_TO_GBOOLEAN(strip),
312312
"Q", quality,
313+
"lossless", INT_TO_GBOOLEAN(lossless),
313314
NULL
314315
);
315316
}

0 commit comments

Comments
 (0)