mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-15 02:15:54 -07:00
feat(#15): more benchmarks
This commit is contained in:
parent
337252c2a0
commit
074a236dc3
4 changed files with 104 additions and 8 deletions
|
|
@ -176,7 +176,7 @@ if err != nil {
|
||||||
|
|
||||||
options := bimg.Watermark{
|
options := bimg.Watermark{
|
||||||
Watermark{
|
Watermark{
|
||||||
Text: "Chuck Norris - Copyright (c) 2315",
|
Text: "Chuck Norris (c) 2315",
|
||||||
Opacity: 0.25,
|
Opacity: 0.25,
|
||||||
Width: 200,
|
Width: 200,
|
||||||
DPI: 100,
|
DPI: 100,
|
||||||
|
|
|
||||||
2
image.go
2
image.go
|
|
@ -75,7 +75,7 @@ func (i *Image) Thumbnail(pixels int) ([]byte, error) {
|
||||||
return i.Process(options)
|
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) {
|
func (i *Image) Watermark(w Watermark) ([]byte, error) {
|
||||||
options := Options{Watermark: w}
|
options := Options{Watermark: w}
|
||||||
return i.Process(options)
|
return i.Process(options)
|
||||||
|
|
|
||||||
|
|
@ -209,7 +209,7 @@ func BenchmarkConvertToJpeg(b *testing.B) {
|
||||||
runBenchmarkResize("test.png", options, b)
|
runBenchmarkResize("test.png", options, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
func BenchmarkCrop(b *testing.B) {
|
func BenchmarkCropJpeg(b *testing.B) {
|
||||||
options := Options{
|
options := Options{
|
||||||
Width: 800,
|
Width: 800,
|
||||||
Height: 600,
|
Height: 600,
|
||||||
|
|
@ -217,6 +217,22 @@ func BenchmarkCrop(b *testing.B) {
|
||||||
runBenchmarkResize("test.jpg", options, 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) {
|
func BenchmarkExtractJpeg(b *testing.B) {
|
||||||
options := Options{
|
options := Options{
|
||||||
Top: 100,
|
Top: 100,
|
||||||
|
|
@ -226,3 +242,83 @@ func BenchmarkExtractJpeg(b *testing.B) {
|
||||||
}
|
}
|
||||||
runBenchmarkResize("test.jpg", options, 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)
|
||||||
|
}
|
||||||
|
|
|
||||||
10
vips.h
10
vips.h
|
|
@ -17,11 +17,11 @@ typedef struct {
|
||||||
} watermarkTextOptions;
|
} watermarkTextOptions;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int Width;
|
int Width;
|
||||||
int DPI;
|
int DPI;
|
||||||
int Margin;
|
int Margin;
|
||||||
int NoReplicate;
|
int NoReplicate;
|
||||||
float Opacity;
|
float Opacity;
|
||||||
double Background[3];
|
double Background[3];
|
||||||
} watermarkOptions;
|
} watermarkOptions;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue