Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
for medium article
package rotateimage-example
import (
"image"
"math"
)
// You can flip the image 90˚ like this
func Rotate90(img image.Image) *image.NRGBA {
src := newScanner(img)
dstW := src.h
dstH := src.w
rowSize := dstW * 4
dst := image.NewNRGBA(image.Rect(0, 0, dstW, dstH))
parallel(0, dstH, func(ys <-chan int) {
for dstY := range ys {
i := dstY * dst.Stride
srcX := dstH - dstY - 1
src.scan(srcX, 0, srcX+1, src.h, dst.Pix[i:i+rowSize])
}
})
return dst
}
// Source: https://github.com/disintegration/imaging/blob/master/transform.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment