Example #1
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
}
Example #2
0
func ApplyFilter(src image.Image, g *gift.GIFT) image.Image {
	dst := image.NewRGBA(g.Bounds(src.Bounds()))
	g.Draw(dst, src)
	return dst
}
Example #3
0
		println("File read failed.")
		return file, err
	}
	// defer f.Close()
	println("File read success.")

	return file, err
}

var _ = Describe("Image", func() {
	var (
		thumbnailFilter *gift.GIFT
		mediumFilter    *gift.GIFT
		err             error
		wb              *bytes.Buffer
		srcImg          *image.Gray
		file            *os.File
		jpegFilename    string
		pngFilename     string
		gifFilename     string
	)

	BeforeEach(func() {
		thumbnailFilter = ThumbnailFilter()
		mediumFilter = MediumFilter()
		srcImg = image.NewGray(image.Rect(0, 0, 10, 20))
		wb = new(bytes.Buffer)
		jpegFilename = "testdata/cat.jpg"
		pngFilename = "testdata/cat.png"
		gifFilename = "testdata/cat.gif"
	})