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
Get Hours, Days, Minutes and Seconds difference between two dates [Future and Past]
Get Year, Month, Day, Hour, Min and Second from a specified date
Select single argument from all arguments of variadic function
Find out how many logical processors used by current process
How to read/write from/to file in Golang?
Example: Stack and Caller from RUNTIME package
Golang HTML parser
Add N number of Year, Month, Day, Hour, Minute, Second, Millisecond, Microsecond and Nanosecond to current date-time
How To Make HTTP Requests in Go?
Passing multiple string arguments to a variadic function