Skip to content

chi-chu/imagescaling

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

imagescaling

imagescaling is a go lib for clip or scaling image. support for jpg/png/bmp/gif 【chaining operations】

imagescaling 是一个go图片 裁剪&缩放&旋转 库。 支持 jpg/png/bmp/gif 格式, 【链式操作】

1.get

go get github/chi-chu/imagescaling

2.Mode Explain

  • CenterClip()  Api example:
      Image text

  • CustomClip(x0, y0, x1, y1 uint)  Api example:
      Image text

  • ProportionScale(p float64)   Api example:
    when p=0.5
      Image text

  • FixScale(height, width uint)   Api example:
    when width=0 height=80
      Image text

  • 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

3.Usage

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)
    }
}

Releases

No releases published

Packages

No packages published

Languages