thumbnail_test.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Copyright 2011 The Graphics-Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package graphics
  5. import (
  6. "code.google.com/p/graphics-go/graphics/graphicstest"
  7. "image"
  8. "testing"
  9. _ "image/png"
  10. )
  11. func TestThumbnailGopher(t *testing.T) {
  12. dst := image.NewRGBA(image.Rect(0, 0, 80, 80))
  13. src, err := graphicstest.LoadImage("../testdata/gopher.png")
  14. if err != nil {
  15. t.Fatal(err)
  16. }
  17. if err := Thumbnail(dst, src); err != nil {
  18. t.Fatal(err)
  19. }
  20. cmp, err := graphicstest.LoadImage("../testdata/gopher-thumb-80x80.png")
  21. if err != nil {
  22. t.Fatal(err)
  23. }
  24. err = graphicstest.ImageWithinTolerance(dst, cmp, 0)
  25. if err != nil {
  26. t.Error(err)
  27. }
  28. }
  29. func TestThumbnailLongGopher(t *testing.T) {
  30. dst := image.NewRGBA(image.Rect(0, 0, 50, 150))
  31. src, err := graphicstest.LoadImage("../testdata/gopher.png")
  32. if err != nil {
  33. t.Fatal(err)
  34. }
  35. if err := Thumbnail(dst, src); err != nil {
  36. t.Fatal(err)
  37. }
  38. cmp, err := graphicstest.LoadImage("../testdata/gopher-thumb-50x150.png")
  39. if err != nil {
  40. t.Fatal(err)
  41. }
  42. err = graphicstest.ImageWithinTolerance(dst, cmp, 0)
  43. if err != nil {
  44. t.Error(err)
  45. }
  46. }