Skip to content

Commit

Permalink
fix: pass quality to image transformer (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
dbarrosop committed May 22, 2023
1 parent 3235e38 commit 5bd777d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
4 changes: 2 additions & 2 deletions client/get_file_information_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@ func TestGetFileInformation(t *testing.T) {
id: testFiles.ProcessedFiles[1].ID,
expected: &client.FileInformationHeader{
CacheControl: "max-age=3600",
ContentLength: 4680,
ContentLength: 6640,
ContentType: "image/jpeg",
Etag: `"ddb70c1d49808c9613c22aea260da98be45b867a0b0eb37d50f4d04d93dfe37a"`,
Etag: `"4ce6e420e7bb5a1c577a9125ce2bc37f950bb9f25f964112308a452985a17912"`,
LastModified: "",
Error: "",
StatusCode: 200,
Expand Down
12 changes: 6 additions & 6 deletions client/get_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func TestGetFile(t *testing.T) {
name: "get image manipulated, if-match==etag",
id: testFiles.ProcessedFiles[1].ID,
opts: []client.GetFileInformationOpt{
client.WithIfMatch(`"038cc03024dfcb9c8947fdcbb2a8b092f5da338c08fea0b948ac36b3be1f6ca9"`),
client.WithIfMatch(`"38aae548d455b164041743d5a0131d93b94fd0f13b2d6aed278469ce29f2328b"`),
client.WithImageSize(600, 200),
client.WithImageQuality(50),
client.WithImageBlur(5),
Expand All @@ -244,14 +244,14 @@ func TestGetFile(t *testing.T) {
Filename: "nhost.jpg",
FileInformationHeader: &client.FileInformationHeader{
CacheControl: "max-age=3600",
ContentLength: 10913,
ContentLength: 6761,
ContentType: "image/jpeg",
Etag: `"038cc03024dfcb9c8947fdcbb2a8b092f5da338c08fea0b948ac36b3be1f6ca9"`,
Etag: `"38aae548d455b164041743d5a0131d93b94fd0f13b2d6aed278469ce29f2328b"`,
LastModified: "Tue, 18 Jan 2022 13:18:04 UTC",
StatusCode: 200,
},
},
expectedSha: "038cc03024dfcb9c8947fdcbb2a8b092f5da338c08fea0b948ac36b3be1f6ca9",
expectedSha: "38aae548d455b164041743d5a0131d93b94fd0f13b2d6aed278469ce29f2328b",
},
{
name: "get image manipulated, if-match!=etag",
Expand All @@ -265,9 +265,9 @@ func TestGetFile(t *testing.T) {
expected: &client.FileInformationHeaderWithReader{
FileInformationHeader: &client.FileInformationHeader{
CacheControl: "max-age=3600",
ContentLength: 10913,
ContentLength: 6761,
ContentType: "image/jpeg",
Etag: `"038cc03024dfcb9c8947fdcbb2a8b092f5da338c08fea0b948ac36b3be1f6ca9"`,
Etag: `"38aae548d455b164041743d5a0131d93b94fd0f13b2d6aed278469ce29f2328b"`,
LastModified: "Tue, 18 Jan 2022 13:18:04 UTC",
StatusCode: 412,
},
Expand Down
13 changes: 7 additions & 6 deletions image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,13 @@ func Manipulate(buf []byte, opts Options) ([]byte, error) {
C.size_t(len(buf)),
&result, //nolint: exhaustruct
C.Options{
width: C.int(opts.Width),
height: C.int(opts.Height),
crop: C.VIPS_INTERESTING_CENTRE,
size: C.VIPS_SIZE_BOTH, //nolint: gocritic
blur: C.double(opts.Blur),
format: C.ImageType(opts.Format), //nolint: gocritic
quality: C.int(opts.Quality),
width: C.int(opts.Width),
height: C.int(opts.Height),
crop: C.VIPS_INTERESTING_CENTRE,
size: C.VIPS_SIZE_BOTH, //nolint: gocritic
blur: C.double(opts.Blur),
format: C.ImageType(opts.Format), //nolint: gocritic
},
)
if err != 0 {
Expand Down
13 changes: 13 additions & 0 deletions image/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,19 @@ func TestManipulate(t *testing.T) {
size uint64
options image.Options
}{
{
name: "jpg",
filename: "testdata/nhost.jpg",
sum: "a88fdb178a6c476e0cb07bdee7a5ffa62d7197dfe54b67cc4a022a36445c6a32",
size: 33399,
options: image.Options{
Height: 100,
Width: 300,
Blur: 2,
Quality: 50,
Format: image.ImageTypeJPEG,
},
},
{
name: "jpg",
filename: "testdata/nhost.jpg",
Expand Down

0 comments on commit 5bd777d

Please sign in to comment.