Skip to content

Commit

Permalink
Add min_size, kmin and kmax options to webp export params
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelsierra committed Jan 26, 2024
1 parent 19be7f9 commit d020afd
Show file tree
Hide file tree
Showing 4 changed files with 17 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

0 comments on commit d020afd

Please sign in to comment.