diff --git a/pkg/thumb/libraw.go b/pkg/thumb/libraw.go index 6f33702..089e5f8 100644 --- a/pkg/thumb/libraw.go +++ b/pkg/thumb/libraw.go @@ -134,6 +134,14 @@ func rotateImg(filePath string, orientation int) error { img = rotate90(rotate90(img)) case 6: img = rotate90(rotate90(rotate90(img))) + case 2: + img = mirrorImg(img) + case 7: + img = rotate90(mirrorImg(img)) + case 4: + img = rotate90(rotate90(mirrorImg(img))) + case 5: + img = rotate90(rotate90(rotate90(mirrorImg(img)))) } if err = resultImg.Truncate(0); err != nil { @@ -252,6 +260,18 @@ func rotate90(img image.Image) image.Image { return newImg } +func mirrorImg(img image.Image) image.Image { + bounds := img.Bounds() + width, height := bounds.Dx(), bounds.Dy() + newImg := image.NewRGBA(image.Rect(0, 0, width, height)) + for x := 0; x < width; x++ { + for y := 0; y < height; y++ { + newImg.Set(width-x-1, y, img.At(x, y)) + } + } + return newImg +} + func (f *LibRawGenerator) Priority() int { return 250 }