mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-05-24 15:52:38 +02:00
test mozJpeg
This commit is contained in:
parent
fee8a037dc
commit
f33c095094
1
go.mod
1
go.mod
@ -23,6 +23,7 @@ require (
|
||||
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
|
||||
github.com/rivo/uniseg v0.4.7 // indirect
|
||||
github.com/stretchr/testify v1.9.0 // indirect
|
||||
github.com/viam-labs/go-libjpeg v0.3.1 // indirect
|
||||
golang.org/x/net v0.25.0 // indirect
|
||||
golang.org/x/sys v0.20.0 // indirect
|
||||
golang.org/x/term v0.20.0 // indirect
|
||||
|
2
go.sum
2
go.sum
@ -39,6 +39,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
github.com/tcnksm/go-latest v0.0.0-20170313132115-e3007ae9052e h1:IWllFTiDjjLIf2oeKxpIUmtiDV5sn71VgeQgg6vcE7k=
|
||||
github.com/tcnksm/go-latest v0.0.0-20170313132115-e3007ae9052e/go.mod h1:d7u6HkTYKSv5m6MCKkOQlHwaShTMl3HjqSGW3XtVhXM=
|
||||
github.com/viam-labs/go-libjpeg v0.3.1 h1:J/byavXHFqRI1PFPrnPbP+wFCr1y+Cn1CwKXrORCPD0=
|
||||
github.com/viam-labs/go-libjpeg v0.3.1/go.mod h1:b0ISpf9lJv9MO1h1gXAmSA/osG19cKGYjfYc6aeEjqs=
|
||||
golang.org/x/image v0.16.0 h1:9kloLAKhUufZhA12l5fwnx2NZW39/we1UhBesW433jw=
|
||||
golang.org/x/image v0.16.0/go.mod h1:ugSZItdV4nOxyqp56HmXwH0Ry0nBCpjnZdpDaIHdoPs=
|
||||
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
|
||||
|
@ -10,6 +10,8 @@ import (
|
||||
"image/jpeg"
|
||||
"image/png"
|
||||
"time"
|
||||
|
||||
mozJpeg "github.com/viam-labs/go-libjpeg/jpeg"
|
||||
)
|
||||
|
||||
type Image struct {
|
||||
@ -28,7 +30,15 @@ func CompressImage(filename string, format string, img image.Image, quality int)
|
||||
case "png":
|
||||
err = png.Encode(&data, img)
|
||||
case "jpeg":
|
||||
err = mozJpeg.Encode(&data, img, &mozJpeg.EncoderOptions{
|
||||
Quality: quality,
|
||||
OptimizeCoding: true,
|
||||
ProgressiveMode: true,
|
||||
DCTMethod: mozJpeg.DCTFloat,
|
||||
})
|
||||
if err != nil && err.Error() == "unsupported image type" {
|
||||
err = jpeg.Encode(&data, img, &jpeg.Options{Quality: quality})
|
||||
}
|
||||
default:
|
||||
err = fmt.Errorf("unknown format %q", format)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user