示例#1
0
func main() {

	if len(os.Args) != 2 {
		fmt.Println("Usage:\tgoimger <file>")
		os.Exit(1)
	}

	srcFileName := os.Args[1]
	srcFile, _ := os.Open(srcFileName)
	src, _, _ := image.Decode(srcFile)

	// let's make a new gift
	g := gift.New(
		gift.Grayscale(),
		gift.UnsharpMask(1.0, 0.5, 0.0),
	)

	// dest - output image
	dest := image.NewRGBA(g.Bounds(src.Bounds()))
	// draw result
	g.Draw(dest, src)

	outFileName := srcFileName + "_goimger.jpg"
	toimg, _ := os.Create(outFileName)
	defer toimg.Close()

	jpeg.Encode(toimg, dest, &jpeg.Options{jpeg.DefaultQuality})
}
示例#2
0
func main() {
	if len(os.Args) != 2 {
		fmt.Println("Usage:\tspiffy <file>")
		os.Exit(1)
	}

	srcFileName := os.Args[1]
	srcFile, _ := os.Open(srcFileName)
	src, _, _ := image.Decode(srcFile)

	// 1. Create a new GIFT and add some filters:
	g := gift.New(
		gift.Grayscale(),
		gift.UnsharpMask(1.0, 1.0, 0.0),
	)

	// 2. Create a new image of the corresponding size.
	// dst is a new target image, src is the original image
	dst := image.NewRGBA(g.Bounds(src.Bounds()))

	// 3. Use Draw func to apply the filters to src and store the result in dst:
	g.Draw(dst, src)

	outFileName := srcFileName + ".spiffy.jpg"
	toimg, _ := os.Create(outFileName)
	defer toimg.Close()

	jpeg.Encode(toimg, dst, &jpeg.Options{jpeg.DefaultQuality})
}