Merge branch 'bugfix/huangbin/compress_image' into 'video-release'

fix: compress image for req

See merge request iesqa/httprunner!30
This commit is contained in:
黄彬
2024-04-01 11:05:21 +00:00
3 changed files with 29 additions and 5 deletions

View File

@@ -1,5 +1,8 @@
# Release History
## v4.3.9 (2023-09-19)
- fix: OCR calls use compressed image
## v4.3.8 (2023-09-19)
- feat: OCR calls use the high-precision cluster interface, and the default timeout is changed from 3s to 10s
- feat: use jpeg to compress screenshots

View File

@@ -1 +1 @@
v4.3.8
v4.3.9

View File

@@ -224,8 +224,30 @@ 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)
if err != nil {
return nil, err
}
default:
return nil, fmt.Errorf("unsupported image format: %s", format)
}
// 返回压缩后的图像数据
return &buf, nil
}
// saveScreenShot saves image file with file name
@@ -252,9 +274,8 @@ func (dExt *DriverExt) saveScreenShot(raw *bytes.Buffer, fileName string) (strin
}()
switch format {
// Convert to jpeg uniformly and compress with a compression rate of 95
case "jpeg", "png":
jpegOptions := &jpeg.Options{Quality: 95}
jpegOptions := &jpeg.Options{}
err = jpeg.Encode(file, img, jpegOptions)
default:
return "", fmt.Errorf("unsupported image format: %s", format)