Skip to content
Open
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions vips/foreign.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ int set_webpload_options(VipsOperation *operation, LoadParams *params) {
MAYBE_SET_INT(operation, params->page, "page");
MAYBE_SET_INT(operation, params->n, "n");
MAYBE_SET_INT(operation, params->access, "access");
MAYBE_SET_DOUBLE(operation, params->webpScale, "scale");
return 0;
}

Expand Down Expand Up @@ -527,6 +528,7 @@ LoadParams create_load_params(ImageType inputFormat) {
.n = defaultParam,
.dpi = defaultParam,
.jpegShrink = defaultParam,
.webpScale = defaultParam,
.heifThumbnail = defaultParam,
.svgUnlimited = defaultParam,
.access = defaultParam,
Expand Down
7 changes: 7 additions & 0 deletions vips/foreign.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,12 @@ func maybeSetIntParam(p IntParameter, cp *C.Param) {
}
}

func maybeSetDoubleParam(p Float64Parameter, cp *C.Param) {
if p.IsSet() {
C.set_double_param(cp, C.gdouble(p.Get()))
}
}

func createImportParams(format ImageType, params *ImportParams) C.LoadParams {
p := C.create_load_params(C.ImageType(format))

Expand All @@ -373,6 +379,7 @@ func createImportParams(format ImageType, params *ImportParams) C.LoadParams {
maybeSetIntParam(params.Page, &p.page)
maybeSetIntParam(params.NumPages, &p.n)
maybeSetIntParam(params.JpegShrinkFactor, &p.jpegShrink)
maybeSetDoubleParam(params.WebpScaleFactor, &p.webpScale)
maybeSetBoolParam(params.HeifThumbnail, &p.heifThumbnail)
maybeSetBoolParam(params.SvgUnlimited, &p.svgUnlimited)
maybeSetIntParam(params.Access, &p.access)
Expand Down
1 change: 1 addition & 0 deletions vips/foreign.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ typedef struct LoadParams {
Param n;
Param dpi;
Param jpegShrink;
Param webpScale;
Param heifThumbnail;
Param svgUnlimited;
Param access;
Expand Down
4 changes: 4 additions & 0 deletions vips/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ type ImportParams struct {
Density IntParameter

JpegShrinkFactor IntParameter
WebpScaleFactor Float64Parameter
HeifThumbnail BoolParameter
SvgUnlimited BoolParameter
Access IntParameter
Expand Down Expand Up @@ -145,6 +146,9 @@ func (i *ImportParams) OptionString() string {
if v := i.JpegShrinkFactor; v.IsSet() {
values = append(values, "shrink="+strconv.Itoa(v.Get()))
}
if v := i.WebpScaleFactor; v.IsSet() {
values = append(values, "scale="+strconv.FormatFloat(v.Get(), 'f', -1, 64))
}
if v := i.AutoRotate; v.IsSet() {
values = append(values, "autorotate="+boolToStr(v.Get()))
}
Expand Down
19 changes: 19 additions & 0 deletions vips/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1927,6 +1927,25 @@ func TestOptionString(t *testing.T) {
})
}

func TestWebpScaleFactor(t *testing.T) {
require.NoError(t, Startup(nil))

params := NewImportParams()
params.WebpScaleFactor.Set(0.5)
img, err := LoadImageFromFile(resources+"webp+alpha.webp", params)
require.NoError(t, err)
defer img.Close()

assert.Equal(t, 400, img.Width())
assert.Equal(t, 300, img.Height())
}

func TestOptionString_WebpScale(t *testing.T) {
p := &ImportParams{}
p.WebpScaleFactor.Set(0.25)
assert.Contains(t, p.OptionString(), "scale=0.25")
}

func TestExportNative_MoreFormats(t *testing.T) {
require.NoError(t, Startup(nil))

Expand Down