imageutil

package
v0.33.6 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2022 License: MIT Imports: 12 Imported by: 12

Documentation

Index

Constants

View Source
const (
	FileExtensionWebp = ".webp"

	FormatNameJPG  = "jpeg"
	FormatNamePNG  = "png"
	FormatNameWEBP = "webp"
)
View Source
const (
	JPEGQualityDefault int = 80
	JPEGQualityMax     int = 100
)

Variables

This section is empty.

Functions

func AddBackgroundColor

func AddBackgroundColor(imgSrc image.Image, clr color.Color) image.Image

AddBackgroundColor adds a background of `color.Color` to an image. It is is useful when the image has a transparent background. Use `colornames` for more colors, e.g. `colornames.Blue`.

func AddBackgroundWhite

func AddBackgroundWhite(imgSrc image.Image) image.Image

AddBackgroundWhite adds a white background which is usable when the image has a transparent background.

func AddBorderRGBA added in v0.33.2

func AddBorderRGBA(img *image.RGBA, clr color.Color, width int) *image.RGBA

func AddBorderRGBAImage added in v0.33.2

func AddBorderRGBAImage(img image.Image, clr color.Color, width int) *image.RGBA

func Aspect

func Aspect(width, height int) float64

func ColsFilteredColor added in v0.33.3

func ColsFilteredColor(img image.Image, c ...color.Color) []int

func ImageAnyToRGBA

func ImageAnyToRGBA(src image.Image) *image.RGBA

func ImageAspect

func ImageAspect(img image.Image) float64

func ImageColors added in v0.33.5

func ImageColors(img image.Image) [][]color.Color

ImageColors returns colors for an image covering the pixels described in `image.Rectangle`: https://pkg.go.dev/image#Rectangle

func ImagePixelCount added in v0.33.2

func ImagePixelCount(img image.Image) int

func ImageToRGBA

func ImageToRGBA(img image.Image) *image.RGBA

func ImageWithSetToRGBA

func ImageWithSetToRGBA(src ImageWithSet) *image.RGBA

func IsImageExt

func IsImageExt(imagePath string) bool

func IsNilOrEmpty

func IsNilOrEmpty(img image.Image) bool

func MergeHorizontalRGBA

func MergeHorizontalRGBA(ims ImageMetaSet) image.Image

MergeHorizontalRGBA returns an image that is composed of non-overlapping imagers in ImageMetaSet. The code here is adapted from https://stackoverflow.com/a/35965499/1908967

func MergeXSameY

func MergeXSameY(images []image.Image, larger bool) image.Image

func MergeXSameYRead

func MergeXSameYRead(locations []string, larger bool) (image.Image, error)

func MergeYSameX

func MergeYSameX(images []image.Image, larger bool) image.Image

func MergeYSameXRead

func MergeYSameXRead(locations []string, larger bool) (image.Image, error)

func NRGBAtoRGBA

func NRGBAtoRGBA(imgNRGBA *image.NRGBA) *image.RGBA

func NegativeOffset

func NegativeOffset(width, height, offset uint) image.Point

func NewRGBAColor

func NewRGBAColor(rect image.Rectangle, clr color.RGBA) *image.RGBA

func NewRGBATransparent

func NewRGBATransparent(rect image.Rectangle) *image.RGBA

func NewRGBAWhite

func NewRGBAWhite(rect image.Rectangle) *image.RGBA

func OverlayCenterYLeftAlign

func OverlayCenterYLeftAlign(imgBg, imgOver image.Image) image.Image

func PaintBorderRGBA

func PaintBorderRGBA(img *image.RGBA, clr color.RGBA, width uint)

func PaintColorRGBA

func PaintColorRGBA(img *image.RGBA, clr color.RGBA)

func PaintColorRGBARectangle

func PaintColorRGBARectangle(img *image.RGBA, clr color.RGBA, rectNew image.Rectangle)

func ParseScaler

func ParseScaler(rawInterpolation string) (draw.Scaler, error)

func ReadImage added in v0.33.3

func ReadImage(location string) (image.Image, string, error)

func ReadImageDimensions

func ReadImageDimensions(imagePath string) (int, int, error)

func ReadImageFile

func ReadImageFile(filename string) (image.Image, string, error)

func ReadImageHttp

func ReadImageHttp(imageUrl string) (image.Image, string, error)

func ReadImages

func ReadImages(locations []string) ([]image.Image, error)

func RectangleBorderXMax

func RectangleBorderXMax(rect image.Rectangle, pixels uint) image.Rectangle

func RectangleBorderXMin

func RectangleBorderXMin(rect image.Rectangle, pixels uint) image.Rectangle

func RectangleBorderYMax

func RectangleBorderYMax(rect image.Rectangle, pixels uint) image.Rectangle

func RectangleBorderYMin

func RectangleBorderYMin(rect image.Rectangle, pixels uint) image.Rectangle

func Resize

func Resize(width, height uint, src image.Image, scale draw.Scaler) image.Image

Resize scales an image to the provided size units. Use a 0 to scale the aspect ratio. See gitub.com/nfnt/resize for Lanczos3, etc. https://github.com/nfnt/resize .

func ResizeFileJPEG

func ResizeFileJPEG(inputFile, outputFile string, outputWidth, outputHeight uint, quality int) error

func ResizeMax

func ResizeMax(maxWidth, maxHeight uint, src image.Image, scale draw.Scaler) image.Image

ResizeMax resizes an image to maximum dimensions. To resize to a maximum of 800 pixels width, the following can be used: `ResizeMax(800, 0, img, nil)`.

func ResizeMaxDimension

func ResizeMaxDimension(maxSide uint, src image.Image, scale draw.Scaler) image.Image

func ResizeMin

func ResizeMin(minWidth, minHeight uint, src image.Image, scale draw.Scaler) image.Image

ResizeMin resizes an image to minimum dimensions. To resize to a minimum of 800 pixels width, the following can be used: `ResizeMin(800, 0, img, nil)`.

func ResizeSameX

func ResizeSameX(images []image.Image, larger bool) []image.Image

func ResizeSameY

func ResizeSameY(images []image.Image, larger bool) []image.Image

func RowsFilteredColor added in v0.33.2

func RowsFilteredColor(img image.Image, c color.Color, cmore ...color.Color) []int

func Scale

func Scale(src image.Image, rect image.Rectangle, scale draw.Scaler) image.Image

Scale will resize the image to the provided rectangle using the provided interpolation function.

func ScalerBest

func ScalerBest() draw.Scaler

func ScalerDefault

func ScalerDefault() draw.Scaler

func SliceXY

func SliceXY(images []image.Image, maxIdx int) (minX, maxX, minY, maxY, sumX, sumY int)

func Square

func Square(src image.Image) image.Image

func WriteFileJPEG

func WriteFileJPEG(filename string, img image.Image, quality int) error

func WriteFilePNG

func WriteFilePNG(filename string, img image.Image) error

func YCbCrToRGBA

func YCbCrToRGBA(src *image.YCbCr) *image.RGBA

Types

type ImageMeta

type ImageMeta struct {
	File       *os.File
	FormatName string
	Image      image.Image
}

func (*ImageMeta) ColorAverage added in v0.33.2

func (meta *ImageMeta) ColorAverage() color.Color

func (*ImageMeta) Height

func (meta *ImageMeta) Height() int

func (*ImageMeta) Stats

func (meta *ImageMeta) Stats() ImageStats

func (*ImageMeta) Width

func (meta *ImageMeta) Width() int

type ImageMetaSet

type ImageMetaSet struct {
	ImageMetas []ImageMeta
}

func NewImageSetFiles

func NewImageSetFiles(filenames []string) (ImageMetaSet, error)

func (*ImageMetaSet) CloseFilesAll

func (ims *ImageMetaSet) CloseFilesAll() error

func (*ImageMetaSet) MaxX

func (ims *ImageMetaSet) MaxX() int

func (*ImageMetaSet) MaxY

func (ims *ImageMetaSet) MaxY() int

func (*ImageMetaSet) Stats

func (ims *ImageMetaSet) Stats() ImageStatsMulti

func (*ImageMetaSet) SumX

func (ims *ImageMetaSet) SumX(maxIndexInclusive int) int

func (*ImageMetaSet) SumY

func (ims *ImageMetaSet) SumY(maxIndexInclusive int) int

type ImageStats

type ImageStats struct {
	Width  int
	Height int
}

func ImageStatsNil

func ImageStatsNil() ImageStats

func ImageStatsRect

func ImageStatsRect(r image.Rectangle) ImageStats

type ImageStatsMulti

type ImageStatsMulti struct {
	MaxX int
	SumX int
	MaxY int
	SumY int
}

type ImageWithSet

type ImageWithSet interface {
	// ColorModel returns the Image's color model.
	ColorModel() color.Model
	// Bounds returns the domain for which At can return non-zero color.
	// The bounds do not necessarily contain the point (0, 0).
	Bounds() image.Rectangle
	// At returns the color of the pixel at (x, y).
	// At(Bounds().Min.X, Bounds().Min.Y) returns the upper-left pixel of the grid.
	// At(Bounds().Max.X-1, Bounds().Max.Y-1) returns the lower-right one.
	At(x, y int) color.Color
	Set(x, y int, c color.Color)
}

type Matrix

type Matrix [][]image.Image

func MatrixRead

func MatrixRead(imglocations [][]string) (Matrix, error)

func (Matrix) AddBackgroundColor

func (matrix Matrix) AddBackgroundColor(clr color.Color)

AddBackgroundColor adds a background of `color.Color` to the images. It is is useful when the image has a transparent background. Use `colornames` for more colors, e.g. `colornames.Blue`.

func (Matrix) AddBackgroundColorHex

func (matrix Matrix) AddBackgroundColorHex(hexcolor string) error

func (Matrix) Merge

func (matrix Matrix) Merge(largerX, largerY bool) image.Image

Merge combines a set of images resizing each row element's height for consistent rows, an each row's width for consistent widths.

Jump to

Keyboard shortcuts

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