diff --git a/README.md b/README.md index f2eab8e..e89e610 100644 --- a/README.md +++ b/README.md @@ -176,7 +176,7 @@ if err != nil { options := bimg.Watermark{ Watermark{ - Text: "Chuck Norris - Copyright (c) 2315", + Text: "Chuck Norris (c) 2315", Opacity: 0.25, Width: 200, DPI: 100, diff --git a/image.go b/image.go index f32606e..fe0d777 100644 --- a/image.go +++ b/image.go @@ -75,7 +75,7 @@ func (i *Image) Thumbnail(pixels int) ([]byte, error) { return i.Process(options) } -// Insert an image to the existent one as watermark +// Add text as watermark on the given image func (i *Image) Watermark(w Watermark) ([]byte, error) { options := Options{Watermark: w} return i.Process(options) diff --git a/resize_test.go b/resize_test.go index 97b91bf..0c29dd6 100644 --- a/resize_test.go +++ b/resize_test.go @@ -209,7 +209,7 @@ func BenchmarkConvertToJpeg(b *testing.B) { runBenchmarkResize("test.png", options, b) } -func BenchmarkCrop(b *testing.B) { +func BenchmarkCropJpeg(b *testing.B) { options := Options{ Width: 800, Height: 600, @@ -217,6 +217,22 @@ func BenchmarkCrop(b *testing.B) { runBenchmarkResize("test.jpg", options, b) } +func BenchmarkCropPng(b *testing.B) { + options := Options{ + Width: 800, + Height: 600, + } + runBenchmarkResize("test.png", options, b) +} + +func BenchmarkCropWebP(b *testing.B) { + options := Options{ + Width: 800, + Height: 600, + } + runBenchmarkResize("test.webp", options, b) +} + func BenchmarkExtractJpeg(b *testing.B) { options := Options{ Top: 100, @@ -226,3 +242,83 @@ func BenchmarkExtractJpeg(b *testing.B) { } runBenchmarkResize("test.jpg", options, b) } + +func BenchmarkExtractPng(b *testing.B) { + options := Options{ + Top: 100, + Left: 50, + AreaWidth: 600, + AreaHeight: 480, + } + runBenchmarkResize("test.png", options, b) +} + +func BenchmarkExtractWebp(b *testing.B) { + options := Options{ + Top: 100, + Left: 50, + AreaWidth: 600, + AreaHeight: 480, + } + runBenchmarkResize("test.webp", options, b) +} + +func BenchmarkZoomJpeg(b *testing.B) { + options := Options{Zoom: 1} + runBenchmarkResize("test.jpg", options, b) +} + +func BenchmarkZoomPng(b *testing.B) { + options := Options{Zoom: 1} + runBenchmarkResize("test.png", options, b) +} + +func BenchmarkZoomWebp(b *testing.B) { + options := Options{Zoom: 1} + runBenchmarkResize("test.webp", options, b) +} + +func BenchmarkWatermarkJpeg(b *testing.B) { + options := Options{ + Watermark: Watermark{ + Text: "Chuck Norris (c) 2315", + Opacity: 0.25, + Width: 200, + DPI: 100, + Margin: 150, + Font: "sans bold 12", + Background: Color{255, 255, 255}, + }, + } + runBenchmarkResize("test.webp", options, b) +} + +func BenchmarkWatermarPng(b *testing.B) { + options := Options{ + Watermark: Watermark{ + Text: "Chuck Norris (c) 2315", + Opacity: 0.25, + Width: 200, + DPI: 100, + Margin: 150, + Font: "sans bold 12", + Background: Color{255, 255, 255}, + }, + } + runBenchmarkResize("test.png", options, b) +} + +func BenchmarkWatermarWebp(b *testing.B) { + options := Options{ + Watermark: Watermark{ + Text: "Chuck Norris (c) 2315", + Opacity: 0.25, + Width: 200, + DPI: 100, + Margin: 150, + Font: "sans bold 12", + Background: Color{255, 255, 255}, + }, + } + runBenchmarkResize("test.webp", options, b) +} diff --git a/vips.h b/vips.h index 0fa7cf9..bdec6b9 100644 --- a/vips.h +++ b/vips.h @@ -17,11 +17,11 @@ typedef struct { } watermarkTextOptions; typedef struct { - int Width; - int DPI; - int Margin; - int NoReplicate; - float Opacity; + int Width; + int DPI; + int Margin; + int NoReplicate; + float Opacity; double Background[3]; } watermarkOptions;