chai2010 / chai2010/webp

对比cwebp命令行,带透明度png图片转换失真明显

Open
#27 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
723
Forks
113
PR merge metrics
No merged PRs in 30d

Description

使用下面代码进行png转webp

```
func ImgTowebp(imgData []byte) ([]byte, error) {
//jpeg.Decode()
img, err := jpeg.Decode(bytes.NewBuffer(imgData))
if err != nil {
//log.Println("decode error from jpg",err)
img, err = png.Decode(bytes.NewBuffer(imgData))
if err != nil {
log.Println("decode error from png or jpg", err)
return nil, err
}
}
//log.Println(fname)
webImgBytes, err := webp.EncodeRGBA(img, 80)
if err == nil {
webpLength := len(webImgBytes)
imgLength := len(imgData)
if webpLength > imgLength {
log.Println("webp bigger than img")
}
log.Println("img2webp :", webpLength, ":", imgLength)
return webImgBytes, nil
} else {
log.Println("webp encode jpg file", err)
return nil, err
}

}

```
对比用cwebp命令行
```
cwebp -q 80 test.png -o test.png.webp
```

发现图片的颜色变化明显,排查源代码没有发现明显错误

测试图片:

![test](https://user-images.githubusercontent.com/492946/71137439-17763f00-2243-11ea-9024-16b6202f83ba.png)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the ImgTowebp example in the issue and reproduce its output using the supplied transparent PNG. Compare that output with cwebp -q 80 and trace the PNG decoding and WebP encoding path. Done means transparent PNG colors no longer differ noticeably from the cwebp result, with a regression test if the project provides a suitable test location.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
computer-graphics
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.