Example #1
0
func blur(img image.Image, howmuch float32) image.Image {
	g := gift.New(gift.Grayscale())
	g.Add(gift.GaussianBlur(howmuch))
	dst := image.NewRGBA(g.Bounds(img.Bounds()))
	g.Draw(dst, img)
	return (dst)
}
Example #2
0
func doit(fn string) (string, error) {
	file, err := os.Open(fn)

	if err != nil {
		return "", err
	}

	defer file.Close()

	img, _, err := image.Decode(file)
	if err != nil {
		return "", err
	}

	b := img.Bounds()
	var g *gift.GIFT

	if b.Max.X-b.Min.X >= resizeThreshold || b.Max.Y-b.Min.Y >= resizeThreshold {
		g = gift.New(
			gift.Resize(resizeSize, resizeSize, gift.LanczosResampling),
			gift.GaussianBlur(sigma))
	} else {
		g = gift.New(gift.GaussianBlur(sigma))
	}

	dst := image.NewRGBA(g.Bounds(img.Bounds()))
	g.Draw(dst, img)
	img = dst

	fn = path.Base(fn)
	ext := path.Ext(fn)
	fn = fmt.Sprintf("./%s.blur%s", fn[:len(fn)-len(ext)], ext)

	w, _ := os.Create(fn)
	defer w.Close()
	if err = jpeg.Encode(w, dst, nil); err != nil {
		return "", err
	}

	return fn, nil
}