polygon

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 10, 2023 License: MIT Imports: 10 Imported by: 0

README

polygon-img

##use golang to crop an image to polygon

Notice:

the point area must be clockwise

Hot to get

go get github.com/dangwan/polygon

test case
func main(){
    f, _ := os.Open("garden.jpeg")
    img, _, _ := image.Decode(f)
        c := polygon.Polygon{
        Width:  img.Bounds().Dx(),
        Height: img.Bounds().Dy(),
        Area: []polygon.Point{
            {200, 0},
            {600, 300},
            {100, 350},
            {0, 100},
        },
    }
    rgbaImg, _ := polygon.ClipForPolygon(&c, img)
}
result show
before

raw

after crop:

after

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClipForPolygon

func ClipForPolygon(t *Polygon, img image.Image) (*image.RGBA, error)

ClipForPolygon clip image to target polygon

func SaveImage

func SaveImage(img image.Image, path string) error

SaveImage save image to local

Types

type Point

type Point struct {
	X float64 `json:"x"`
	Y float64 `json:"Y"`
}

Point 判断点是否位于区域内,此方法只适用于矩形,无法应用于所有情况

type Polygon

type Polygon struct {
	//X      int     `json:"x"`
	//Y      int     `json:"y"`
	Width  int     `json:"width"`
	Height int     `json:"height"`
	Area   []Point `json:"area"` // 顺时针坐标
}

Polygon 目标图片多边形信息

func (*Polygon) At

func (c *Polygon) At(x, y int) color.Color

At judge point alpha

func (*Polygon) Bounds

func (c *Polygon) Bounds() image.Rectangle

Bounds set image bounds

func (*Polygon) ColorModel

func (c *Polygon) ColorModel() color.Model

ColorModel set color model

func (*Polygon) PointInArea

func (c *Polygon) PointInArea(x, y float64) bool

PointInArea 判断一个点是否在一个面内

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL