mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-08 23:18:19 -07:00
Add support for image watermarks
This commit is contained in:
parent
2ccb6aa8a7
commit
1a661e4e52
9 changed files with 325 additions and 26 deletions
|
|
@ -239,7 +239,34 @@ func TestImageWatermark(t *testing.T) {
|
|||
t.Fatal("Image is not jpeg")
|
||||
}
|
||||
|
||||
Write("fixtures/test_watermark_out.jpg", buf)
|
||||
Write("fixtures/test_watermark_text_out.jpg", buf)
|
||||
}
|
||||
|
||||
func TestImageWatermarkWithImage(t *testing.T) {
|
||||
image := initImage("test.jpg")
|
||||
watermark, _ := imageBuf("transparent.png")
|
||||
|
||||
_, err := image.Crop(800, 600, GravityNorth)
|
||||
if err != nil {
|
||||
t.Errorf("Cannot process the image: %#v", err)
|
||||
}
|
||||
|
||||
buf, err := image.WatermarkImage(WatermarkImage{Left: 100, Top: 100, Buf: watermark})
|
||||
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
err = assertSize(buf, 800, 600)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if DetermineImageType(buf) != JPEG {
|
||||
t.Fatal("Image is not jpeg")
|
||||
}
|
||||
|
||||
Write("fixtures/test_watermark_image_out.jpg", buf)
|
||||
}
|
||||
|
||||
func TestImageWatermarkNoReplicate(t *testing.T) {
|
||||
|
|
@ -429,10 +456,14 @@ func TestFluentInterface(t *testing.T) {
|
|||
}
|
||||
|
||||
func initImage(file string) *Image {
|
||||
buf, _ := Read(path.Join("fixtures", file))
|
||||
buf, _ := imageBuf(file)
|
||||
return NewImage(buf)
|
||||
}
|
||||
|
||||
func imageBuf(file string) ([]byte, error) {
|
||||
return Read(path.Join("fixtures", file))
|
||||
}
|
||||
|
||||
func assertSize(buf []byte, width, height int) error {
|
||||
size, err := NewImage(buf).Size()
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue