func (s *ResizeSuite) TestResizeImageSquare(c *C) {
	file, err := ioutil.ReadFile("test/awesome.jpeg")
	c.Assert(err, IsNil)

	for width, _ := range sizes {
		ctx := &fetch.CacheContext{
			Width: width,
			Crop:  true,
		}

		buf := bytes.NewReader(file)
		resized, err := fetch.Resize(buf, ctx)
		c.Check(err, IsNil)

		image, _, err := image.Decode(resized)
		c.Check(err, IsNil)

		if width > 768 {
			width = 768
		}

		c.Check(image.Bounds().Size().X, Equals, width)
		c.Check(image.Bounds().Size().Y, Equals, width)
	}
}
func (s *ResizeSuite) TestResizeImage(c *C) {
	file, err := ioutil.ReadFile("test/exif_test_img.jpg")
	c.Assert(err, IsNil)

	for width, height := range sizes {
		ctx := &fetch.CacheContext{
			Width: width,
		}

		data := bytes.NewBuffer(file)

		orig, _, err := fetch.GetRotatedImage(data)
		c.Check(err, IsNil)

		buf := new(bytes.Buffer)
		jpeg.Encode(buf, orig, nil)

		resized, err := fetch.Resize(buf, ctx)
		c.Check(err, IsNil)

		image, _, err := image.Decode(resized)
		c.Check(err, IsNil)
		c.Check(image.Bounds().Size().X, Equals, width)
		c.Check(image.Bounds().Size().Y, Equals, height)
	}
}
func (s *ResizeSuite) BenchmarkLargeResize(c *C) {
	file, err := ioutil.ReadFile("test/awesome.jpeg")
	c.Assert(err, IsNil)

	ctx := &fetch.CacheContext{
		Width: 720,
	}

	for i := 0; i < c.N; i++ {
		// Need a new io.Reader on every iteration
		buf := bytes.NewReader(file)
		_, err := fetch.Resize(buf, ctx)
		c.Check(err, IsNil)
	}
}
func (s *ResizeSuite) TestResizeOversizedImageSquare(c *C) {
	file, err := ioutil.ReadFile("test/awesome-small.jpg")
	c.Assert(err, IsNil)

	ctx := &fetch.CacheContext{
		Width: 400,
		Crop:  true,
	}

	buf := bytes.NewReader(file)
	resized, err := fetch.Resize(buf, ctx)
	c.Check(err, IsNil)

	image, _, err := image.Decode(resized)
	c.Check(err, IsNil)
	c.Check(image.Bounds().Size().X, Equals, 150)
	c.Check(image.Bounds().Size().Y, Equals, 150)
}
func (s *ResizeSuite) TestResizeNoExifImage(c *C) {
	file, err := ioutil.ReadFile("test/AWESOME.jpg")
	c.Assert(err, IsNil)

	for width, height := range noExifSizes {
		ctx := &fetch.CacheContext{
			Width: width,
		}

		buf := bytes.NewReader(file)
		resized, err := fetch.Resize(buf, ctx)
		c.Check(err, IsNil)

		image, _, err := image.Decode(resized)
		c.Check(err, IsNil)
		c.Check(image.Bounds().Size().X, Equals, width)
		c.Check(image.Bounds().Size().Y, Equals, height)
	}
}