mirror of
https://github.com/willnorris/imageproxy.git
synced 2026-05-09 12:02:39 +02:00
add minimum support for primitive library
use primitive library to draw simplified version of image with basic shapes.
This commit is contained in:
parent
95bcf70004
commit
0d5d8aa202
4 changed files with 48 additions and 1 deletions
22
transform.go
22
transform.go
|
|
@ -13,8 +13,10 @@ import (
|
|||
"io"
|
||||
"log"
|
||||
"math"
|
||||
"runtime"
|
||||
|
||||
"github.com/disintegration/imaging"
|
||||
"github.com/fogleman/primitive/primitive"
|
||||
"github.com/muesli/smartcrop"
|
||||
"github.com/muesli/smartcrop/nfnt"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
|
|
@ -309,5 +311,25 @@ func transformImage(m image.Image, opt Options) image.Image {
|
|||
m = imaging.FlipH(m)
|
||||
}
|
||||
|
||||
if opt.Primitive.Count > 0 {
|
||||
model := transformPrimitive(m, opt)
|
||||
m = model.Context.Image()
|
||||
}
|
||||
|
||||
return m
|
||||
}
|
||||
|
||||
func transformPrimitive(m image.Image, opt Options) *primitive.Model {
|
||||
// set size to the longest of height or width
|
||||
size := m.Bounds().Size().X
|
||||
if h := m.Bounds().Size().Y; size < h {
|
||||
size = h
|
||||
}
|
||||
|
||||
bg := primitive.MakeColor(primitive.AverageImageColor(m))
|
||||
model := primitive.NewModel(m, bg, size, runtime.NumCPU())
|
||||
for i := 0; i < opt.Primitive.Count; i++ {
|
||||
model.Step(primitive.ShapeType(opt.Primitive.Mode), 128, 0)
|
||||
}
|
||||
return model
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue