Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add min_size, kmin and kmax options to webp export params #400

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading