imagorpath

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2022 License: Apache-2.0 Imports: 9 Imported by: 1

README

imagorpath

Parse and generate Imagor endpoint using Go struct

import "github.com/cshum/imagor/imagorpath"

...

func Test(t *testing.T) {
	params := imagorpath.Params{
		Image:    "raw.githubusercontent.com/cshum/imagor/master/testdata/gopher.png",
		FitIn:    true,
		Width:    500,
		Height:   400,
		VPadding: 20,
		Filters: imagorpath.Filters{
			{
				Name: "fill",
				Args: "white",
			},
		},
	}

	// generate signed Imagor endpoint from Params struct with secret
	path := imagorpath.Generate(params, "mysecret")

	assert.Equal(t, path, "OyGJyvfYJw8xNkYDmXU-4NPA2U0=/fit-in/500x400/0x20/filters:fill(white)/raw.githubusercontent.com/cshum/imagor/master/testdata/gopher.png")

	assert.Equal(t,
		// parse Params struct from signed Imagor endpoint
		imagorpath.Parse(path),

		// Params include endpoint attributes with path and signed hash
		imagorpath.Params{
			Path:     "fit-in/500x400/0x20/filters:fill(white)/raw.githubusercontent.com/cshum/imagor/master/testdata/gopher.png",
			Hash:     "OyGJyvfYJw8xNkYDmXU-4NPA2U0=",
			Image:    "raw.githubusercontent.com/cshum/imagor/master/testdata/gopher.png",
			FitIn:    true,
			Width:    500,
			Height:   400,
			VPadding: 20,
			Filters: imagorpath.Filters{
				{
					Name: "fill",
					Args: "white",
				},
			},
		},
	)
}

Documentation

Index

Constants

View Source
const (
	TrimByTopLeft     = "top-left"
	TrimByBottomRight = "bottom-right"
	HAlignLeft        = "left"
	HAlignRight       = "right"
	VAlignTop         = "top"
	VAlignBottom      = "bottom"
)

Variables

This section is empty.

Functions

func Generate

func Generate(p Params, secret string) string

Generate Imagor endpoint with signature by Params struct with secret

func GenerateUnsafe

func GenerateUnsafe(p Params) string

GenerateUnsafe generate unsafe Imagor endpoint by Params struct

func Normalize added in v0.5.15

func Normalize(image string, shouldEscape ...func(c byte) bool) string

Normalize imagor path to be file path friendly, optional shouldEscape func to define safe characters

func Sign

func Sign(path, secret string) string

Sign an Imagor endpoint with secret key

Types

type Filter

type Filter struct {
	Name string `json:"name,omitempty"`
	Args string `json:"args,omitempty"`
}

type Filters

type Filters []Filter

type Params

type Params struct {
	Params        bool    `json:"-"`
	Path          string  `json:"path,omitempty"`
	Image         string  `json:"image,omitempty"`
	Unsafe        bool    `json:"unsafe,omitempty"`
	Hash          string  `json:"hash,omitempty"`
	Meta          bool    `json:"meta,omitempty"`
	Trim          bool    `json:"trim,omitempty"`
	TrimBy        string  `json:"trim_by,omitempty"`
	TrimTolerance int     `json:"trim_tolerance,omitempty"`
	CropLeft      int     `json:"crop_left,omitempty"`
	CropTop       int     `json:"crop_top,omitempty"`
	CropRight     int     `json:"crop_right,omitempty"`
	CropBottom    int     `json:"crop_bottom,omitempty"`
	FitIn         bool    `json:"fit_in,omitempty"`
	Stretch       bool    `json:"stretch,omitempty"`
	Width         int     `json:"width,omitempty"`
	Height        int     `json:"height,omitempty"`
	HPadding      int     `json:"h_padding,omitempty"`
	VPadding      int     `json:"v_padding,omitempty"`
	HFlip         bool    `json:"h_flip,omitempty"`
	VFlip         bool    `json:"v_flip,omitempty"`
	HAlign        string  `json:"h_align,omitempty"`
	VAlign        string  `json:"v_align,omitempty"`
	Smart         bool    `json:"smart,omitempty"`
	Filters       Filters `json:"filters,omitempty"`
}

Params image endpoint parameters

func Parse

func Parse(path string) (p Params)

Parse Params struct from Imagor endpoint URI

Jump to

Keyboard shortcuts

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