imager

package module
v0.0.0-...-dd2be37 Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IMJPEG string = "jpeg"
	IMJPG  string = "jpg"
	IMGIF  string = "gif"
	IMPNG  string = "png"
	IMWEBP string = "webp"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Imager

type Imager struct {
	Image     image.Image
	ImageType string
}

Imager is a struct that can be used to manipulate an image

func NewImager

func NewImager(img image.Image) (*Imager, error)

NewImager creates a new Imager i.e : imgr, err := imager.NewImager(img)

func NewImagerFromBytes

func NewImagerFromBytes(data []byte) (*Imager, error)

NewImagerFromBytes creates a new Imager from bytes i.e : imgr, err := imager.NewImagerFromBytes(data)

func NewImagerFromFile

func NewImagerFromFile(location string) (*Imager, error)

NewImagerFromFile creates a new Imager from a file i.e : imgr, err := imager.NewImagerFromFile("image.jpg")

func (*Imager) Bytes

func (i *Imager) Bytes() ([]byte, error)

Bytes returns the image as a byte array

func (*Imager) Crop

func (i *Imager) Crop(width, height int, x, y int) *Imager

Crop crops the image

func (*Imager) LoadByte

func (i *Imager) LoadByte(data []byte) error

LoadByte loads a byte array into the image

func (*Imager) LoadFile

func (i *Imager) LoadFile(location string) error

LoadFile loads a file into the image

func (*Imager) Resize

func (i *Imager) Resize(width, height int, modes ...ResizeMode) *Imager

Resize resizes the image i.e : imgr.Resize(100, 100, imager.MD_FIT) imgr.Resize(100, 100, imager.MD_CROP) imgr.Resize(100, 100, imager.MD_SCALE)

func (*Imager) Rotate

func (i *Imager) Rotate(degrees int) *Imager

Rotate rotates the image

func (*Imager) Save

func (i *Imager) Save(location string) error

Save saves the image

type ResizeMode

type ResizeMode int

ResizeMode is a flag that can be used to resize an image

const (
	// MD_FIT - Fit the image within the specified dimensions, maintaining the aspect ratio
	MD_FIT ResizeMode = iota

	// MD_CROP - Crop the image to the center
	MD_CROP

	// MD_SCALE - Resize keeping the aspect ratio
	MD_SCALE

	// MD_STRETCH - Resize to exact dimensions without keeping the aspect ratio
	MD_STRETCH
)

Jump to

Keyboard shortcuts

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