Skip to content

Commit

Permalink
Return PNG images as it is when JPEG quality is set to 100
Browse files Browse the repository at this point in the history
  • Loading branch information
albertusdev committed Jul 16, 2019
1 parent 1426ed3 commit 2b560f6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/processor/native/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (e *Encoders) GetEncoder(img image.Image, ext string) Encoder {
return e.jpegEncoder
}
if ext == "png" {
if isOpaque(img) {
if e.options.JpegQuality != 100 && isOpaque(img) {
return e.jpegEncoder
}
return e.pngEncoder
Expand Down
4 changes: 4 additions & 0 deletions pkg/processor/native/encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@ func (s *EncoderSuite) TestEncoders_GetEncoder() {
assert.True(s.T(), ok)
_, ok = (encoders.GetEncoder(image.Opaque, "jpeg")).(*JpegEncoder)
assert.True(s.T(), ok)
encoders.options.JpegQuality = 99
_, ok = (encoders.GetEncoder(image.Opaque, "png")).(*JpegEncoder)
assert.True(s.T(), ok)
encoders.options.JpegQuality = 100
_, ok = (encoders.GetEncoder(image.Opaque, "png")).(*PngEncoder)
assert.True(s.T(), ok)
_, ok = (encoders.GetEncoder(image.Transparent, "png")).(*PngEncoder)
assert.True(s.T(), ok)
_, ok = (encoders.GetEncoder(image.Black, "unknown")).(*NopEncoder)
Expand Down

0 comments on commit 2b560f6

Please sign in to comment.