imagescaling is a go lib for clip or scaling image. support for jpg/png/bmp/gif 【chaining operations】
imagescaling 是一个go图片 裁剪&缩放&旋转 库。 支持 jpg/png/bmp/gif 格式, 【链式操作】
go get github/chi-chu/imagescaling
-
FixScale(height, width uint) Api example:
when width=0 height=80
-
Rotate(RotateMode) Api example:
clockwise only support 90/180/270 degrees
Rotate90Degrees Rotate180Degrees Rotate270Degrees -
ReSet() Api Desc:
Recover the image to original data -
GetExt() Api Desc:
Get the file type jpg/png/bmp/gif
import github/chi-chu/imagescaling
func main(){
imageData, err := os.Open("/your/image/path/filename.jpg")
if err != nil {
panic(err)
}
defer imageData.Close()
img, err := imagescaling.New(imageData)
if err != nil {
panic(err)
}
outPutPath := "/your/output/image/path/filename."+ img.GetExt()
fd, err := os.OpenFile(outPutPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0777)
if err != nil {
panic(err)
}
defer fd.Close()
err = img.CustomClip(100, 23, 400, 300).FixScale(100, 0).Rotate(imagescaling.Rotate90Degrees).Draw(fd)
if err != nil {
panic(err)
}
}