Skip to content

Instantly share code, notes, and snippets.

@hackintoshrao
Created February 22, 2017 00:44
Show Gist options
  • Select an option

  • Save hackintoshrao/45a0527803a3c843a55e861cb94fdcb2 to your computer and use it in GitHub Desktop.

Select an option

Save hackintoshrao/45a0527803a3c843a55e861cb94fdcb2 to your computer and use it in GitHub Desktop.
Thubnail generator for golang.
package main
import (
"image"
"image/color"
"github.com/disintegration/imaging"
)
func main() {
// input files
file := "1.jpg"
// load images and make 100x100 thumbnails of them
var thumbnail image.Image
img, err := imaging.Open(file)
if err != nil {
panic(err)
}
thumbnail = imaging.Thumbnail(img, 100, 100, imaging.CatmullRom)
// create a new blank image
dst := imaging.New(100, 100, color.NRGBA{0, 0, 0, 0})
// paste thumbnails into the new image side by side
dst = imaging.Paste(dst, thumbnail, image.Pt(0, 0))
// save the combined image to file
err = imaging.Save(dst, "dst.jpg")
if err != nil {
panic(err)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment