Skip to content

Commit

Permalink
Add min_size, kmin and kmax options to webp export params (#400)
Browse files Browse the repository at this point in the history
* Add min_size, kmin and kmax options to webp export params

* Add test to new extra params
  • Loading branch information
rafaelsierra authored Jan 28, 2024
1 parent 19be7f9 commit 44d974d
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions vips/foreign.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ int set_webpsave_options(VipsOperation *operation, SaveParams *params) {
"near_lossless", params->webpNearLossless,
"reduction_effort", params->webpReductionEffort,
"profile", params->webpIccProfile ? params->webpIccProfile : "none",
"min_size", params->webpMinSize,
"kmin", params->webpKMin,
"kmax", params->webpKMax,
NULL);

if (!ret && params->quality) {
Expand Down Expand Up @@ -542,6 +545,9 @@ static SaveParams defaultSaveParams = {
.webpNearLossless = FALSE,
.webpReductionEffort = 4,
.webpIccProfile = NULL,
.webpKMax = 0,
.webpKMin = 0,
.webpMinSize = FALSE,

.heifBitdepth = 8,
.heifLossless = FALSE,
Expand Down
3 changes: 3 additions & 0 deletions vips/foreign.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,9 @@ func vipsSaveWebPToBuffer(in *C.VipsImage, params WebpExportParams) ([]byte, err
p.webpLossless = C.int(boolToInt(params.Lossless))
p.webpNearLossless = C.int(boolToInt(params.NearLossless))
p.webpReductionEffort = C.int(params.ReductionEffort)
p.webpMinSize = C.int(boolToInt(params.MinSize))
p.webpKMin = C.int(params.MinKeyFrames)
p.webpKMax = C.int(params.MaxKeyFrames)

if params.IccProfile != "" {
p.webpIccProfile = C.CString(params.IccProfile)
Expand Down
3 changes: 3 additions & 0 deletions vips/foreign.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ typedef struct SaveParams {
BOOL webpNearLossless;
int webpReductionEffort;
char *webpIccProfile;
BOOL webpMinSize;
int webpKMin;
int webpKMax;

// HEIF - https://github.com/libvips/libvips/blob/master/libvips/foreign/heifsave.c#L71
int heifBitdepth; // Bitdepth to save at for >8 bit images
Expand Down
5 changes: 5 additions & 0 deletions vips/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -272,13 +272,18 @@ func NewPngExportParams() *PngExportParams {
}

// WebpExportParams are options when exporting a WEBP to file or buffer
// see https://www.libvips.org/API/current/VipsForeignSave.html#vips-webpsave
// for details on each parameter
type WebpExportParams struct {
StripMetadata bool
Quality int
Lossless bool
NearLossless bool
ReductionEffort int
IccProfile string
MinSize bool
MinKeyFrames int
MaxKeyFrames int
}

// NewWebpExportParams creates default values for an export of a WEBP image.
Expand Down
12 changes: 12 additions & 0 deletions vips/image_gif_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ func TestImage_GIF_Animated_to_WebP(t *testing.T) {
exportWebp(NewWebpExportParams()))
}

func TestImage_GIF_Animated_to_WebP_Extra_Params(t *testing.T) {
exportParams := NewWebpExportParams()
exportParams.MaxKeyFrames = 100
exportParams.MinKeyFrames = 10
exportParams.MinSize = true
goldenAnimatedTest(t, resources+"gif-animated.gif",
3,
nil,
nil,
exportWebp(exportParams))
}

func TestImage_GIF_Animated_Resize(t *testing.T) {
goldenAnimatedTest(t, resources+"gif-animated.gif",
3,
Expand Down

0 comments on commit 44d974d

Please sign in to comment.