mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-18 17:07:35 +08:00
fix: compress image for req
This commit is contained in:
@@ -224,8 +224,27 @@ func (dExt *DriverExt) takeScreenShot(fileName string) (raw *bytes.Buffer, path
|
||||
}
|
||||
|
||||
func compressImageBuffer(raw *bytes.Buffer) (compressed *bytes.Buffer, err error) {
|
||||
// TODO: compress image data
|
||||
return raw, nil
|
||||
// 解码原始图像数据
|
||||
img, format, err := image.Decode(raw)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 创建一个用来保存压缩后数据的buffer
|
||||
var buf bytes.Buffer
|
||||
|
||||
switch format {
|
||||
// Convert to jpeg uniformly and compress with a compression rate of 95
|
||||
case "jpeg", "png":
|
||||
jpegOptions := &jpeg.Options{Quality: 95}
|
||||
err = jpeg.Encode(&buf, img, jpegOptions)
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported image format: %s", format)
|
||||
}
|
||||
|
||||
// 返回压缩后的图像数据
|
||||
return &buf, nil
|
||||
|
||||
}
|
||||
|
||||
// saveScreenShot saves image file with file name
|
||||
|
||||
Reference in New Issue
Block a user