How to create thumbnail of an image?
In dstImage the size 80 X 80 passed to create thumbnail of 80px 80px. Google graphics package used to generate thumbnail of image.
Example
package main
import (
"os"
"image"
"image/jpeg"
"code.google.com/p/graphics-go/graphics"
)
func main() {
imagePath, _ := os.Open("jellyfish.jpg")
defer imagePath.Close()
srcImage, _, _ := image.Decode(imagePath)
// Dimension of new thumbnail 80 X 80
dstImage := image.NewRGBA(image.Rect(0, 0, 80, 80))
// Thumbnail function of Graphics
graphics.Thumbnail(dstImage, srcImage)
newImage, _ := os.Create("thumbnail.jpg")
defer newImage.Close()
jpeg.Encode(newImage, dstImage, &jpeg.Options{jpeg.DefaultQuality})
}
Most Helpful This Week
How to check if a string contains only letters in Golang?
Golang Get current Date and Time in EST, UTC and MST?
How to get struct variable information using reflect package?
Golang Convert String into Snake Case
How to find length of Map in Go?
Find element in a slice and move it to first position?
How to fetch an Integer variable as String in Go?
Create and Print Multi Dimensional Slice in Golang
How to add Watermark or Merge two image?
How to convert Boolean Type to String in Go?