Golang how to concatenate/append images to one another

前端 未结 3 966
迷失自我
迷失自我 2020-12-28 09:44

Go has great image manipulation and data libraries however I\'m having trouble creating one big image from smaller ones. Does anyone know how to take two png or jpeg files

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-28 09:48

    I built a library exactly for this purpose.

    You can use it as follows;

    import gim "github.com/ozankasikci/go-image-merge"
    
    grids := []*gim.Grid{
        {ImageFilePath: "test1.jpg"},
        {ImageFilePath: "test2.png"},
    }
    
    // merge the images into a 2x1 grid
    rgba, err := gim.New(grids, 2, 1).Merge()
    
    // save the output to jpg or png
    file, err := os.Create("file/path.jpg|png")
    err = jpeg.Encode(file, rgba, &jpeg.Options{Quality: 80})
    

    https://github.com/ozankasikci/go-image-merge

提交回复
热议问题