webp fix v2
This commit is contained in:
@@ -106,6 +106,16 @@ func tiffOrientation(tiff []byte) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
// orientationSwapsDimensions 报告该 Orientation 是否会交换宽高。
|
||||
// 2/3/4 只是镜像或 180 度旋转,宽高不变;5/6/7/8 会把横躺的像素转正,宽高互换。
|
||||
func orientationSwapsDimensions(orientation int) bool {
|
||||
switch orientation {
|
||||
case exifOrientLeftTop, exifOrientRightTop, exifOrientRightBottom, exifOrientLeftBottom:
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// orientedImage 把源图按 EXIF Orientation 重映射为目标坐标,供 draw.Draw
|
||||
// 一次性拷贝,避免逐像素重复计算源矩形。
|
||||
type orientedImage struct {
|
||||
@@ -158,9 +168,8 @@ func applyJPEGOrientation(img image.Image, orientation int) image.Image {
|
||||
return img
|
||||
}
|
||||
dstW, dstH := sw, sh
|
||||
switch orientation {
|
||||
case exifOrientLeftTop, exifOrientRightTop, exifOrientRightBottom, exifOrientLeftBottom:
|
||||
dstW, dstH = sh, sw // 这四种会交换宽高
|
||||
if orientationSwapsDimensions(orientation) {
|
||||
dstW, dstH = sh, sw
|
||||
}
|
||||
|
||||
dst := image.NewRGBA(image.Rect(0, 0, dstW, dstH))
|
||||
|
||||
Reference in New Issue
Block a user