Skip to content

Commit

Permalink
Add a test case for #177.
Browse files Browse the repository at this point in the history
Signed-off-by: Yoan Blanc <[email protected]>
  • Loading branch information
greut committed Aug 21, 2017
1 parent bac8e42 commit a94b99f
Showing 1 changed file with 34 additions and 22 deletions.
56 changes: 34 additions & 22 deletions image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,33 +213,45 @@ func TestImageThumbnail(t *testing.T) {
}

func TestImageWatermark(t *testing.T) {
image := initImage("test.jpg")
_, err := image.Crop(800, 600, GravityNorth)
if err != nil {
t.Errorf("Cannot process the image: %#v", err)
files := []struct {
Name string
Type ImageType
}{
{"test.jpg", JPEG},
{"test.png", PNG},
}

buf, err := image.Watermark(Watermark{
Text: "Copy me if you can",
Opacity: 0.5,
Width: 200,
DPI: 100,
Background: Color{255, 255, 255},
})
if err != nil {
t.Error(err)
}
for _, file := range files {
image := initImage(file.Name)
_, err := image.Crop(800, 600, GravityNorth)
if err != nil {
t.Errorf("Cannot process the image: %#v", err)
continue
}

err = assertSize(buf, 800, 600)
if err != nil {
t.Error(err)
}
buf, err := image.Watermark(Watermark{
Text: "Copy me if you can",
Opacity: 0.5,
Width: 200,
DPI: 100,
Background: Color{255, 255, 255},
})
if err != nil {
t.Errorf("Watermark failure: %s", err)
continue
}

if DetermineImageType(buf) != JPEG {
t.Fatal("Image is not jpeg")
}
err = assertSize(buf, 800, 600)
if err != nil {
t.Error(err)
continue
}

Write("fixtures/test_watermark_text_out.jpg", buf)
tp := DetermineImageType(buf)
if tp != file.Type {
t.Errorf("Image is not %v, got %v", ImageTypeName(file.Type), ImageTypeName(tp))
}
}
}

func TestImageWatermarkWithImage(t *testing.T) {
Expand Down

0 comments on commit a94b99f

Please sign in to comment.