img

package
v0.0.0-...-60192f8 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Overview

Package img provides a unified image loader and manipulation pipeline. It can load images using the native go implementations for the major web image types, perform some manipulation like resizing and write the result to an io.Writer.

Index

Constants

This section is empty.

Variables

View Source
var Gray16Palette = []color.Color{
	color.RGBA{0x00, 0x00, 0x00, 0xff},
	color.RGBA{0x11, 0x11, 0x11, 0xff},
	color.RGBA{0x22, 0x22, 0x22, 0xff},
	color.RGBA{0x33, 0x33, 0x33, 0xff},
	color.RGBA{0x44, 0x44, 0x44, 0xff},
	color.RGBA{0x55, 0x55, 0x55, 0xff},
	color.RGBA{0x66, 0x66, 0x66, 0xff},
	color.RGBA{0x77, 0x77, 0x77, 0xff},
	color.RGBA{0x88, 0x88, 0x88, 0xff},
	color.RGBA{0x99, 0x99, 0x99, 0xff},
	color.RGBA{0xaa, 0xaa, 0xaa, 0xff},
	color.RGBA{0xbb, 0xbb, 0xbb, 0xff},
	color.RGBA{0xcc, 0xcc, 0xcc, 0xff},
	color.RGBA{0xdd, 0xdd, 0xdd, 0xff},
	color.RGBA{0xee, 0xee, 0xee, 0xff},
	color.RGBA{0xff, 0xff, 0xff, 0xff},
}

Gray16Palette is a 16 level b&w palette.

Functions

func AddImageHandler

func AddImageHandler(f Handler, types ...string)

AddImageHandler adds (or replaces) a handler for the given types.

func Fit

func Fit(im Image, w, h uint) error

Fit resizes the image keeping the aspect ratio and staying within the given width and height.

func Pipeline

func Pipeline(im Image, filters ...ImageFilter) error

Pipeline apply all the given ImageFilter functions to the image.

Types

type Handler

type Handler func(io.Reader) (Image, error)

Handler is a function that returns an Image type instance from an io.Reader.

type Image

type Image interface {
	Close() error
	Format() string
	ContentType() string
	Width() uint
	Height() uint
	SetFormat(string) error
	Resize(uint, uint) error
	Encode(io.Writer) error
	SetCompression(ImageCompression) error
	SetQuality(uint8) error
	Grayscale() error
	Gray16() error
	Clean() error
}

Image describes the interface of an image manipulation type.

func New

func New(contentType string, r io.Reader) (Image, error)

New creates a new Image instance, using the available handlers.

type ImageCompression

type ImageCompression uint8

ImageCompression is the compression level used for PNG images.

const (
	// CompressionFast is a fast method.
	CompressionFast ImageCompression = iota

	// CompressionBest is the best space saving method.
	CompressionBest
)

type ImageFilter

type ImageFilter func(Image) error

ImageFilter is a filter application function used by the Pipeline method of an Image instance.

type NativeImage

type NativeImage struct {
	// contains filtered or unexported fields
}

NativeImage is the Image implementation using Go native image tools.

func NewNativeImage

func NewNativeImage(r io.Reader) (*NativeImage, error)

NewNativeImage returns a NativeImage instance using Go native image tools.

func (*NativeImage) Clean

func (im *NativeImage) Clean() error

Clean is a noop function for this image family.

func (*NativeImage) Close

func (im *NativeImage) Close() error

Close frees the resources used by the image and must be called when you're done processing it.

func (*NativeImage) ContentType

func (im *NativeImage) ContentType() string

ContentType returns the image mimetype.

func (*NativeImage) Encode

func (im *NativeImage) Encode(w io.Writer) error

Encode encodes the image to an io.Writer.

func (*NativeImage) Format

func (im *NativeImage) Format() string

Format returns the image format.

func (*NativeImage) Gray16

func (im *NativeImage) Gray16() error

Gray16 transforms the image to a 16 gray levels palette, applying a Floyd Steinberg dithering. It is better to convert the image to grayscale before this operation.

func (*NativeImage) Grayscale

func (im *NativeImage) Grayscale() error

Grayscale transforms the image to a grayscale version.

func (*NativeImage) Height

func (im *NativeImage) Height() uint

Height returns the image height.

func (*NativeImage) Image

func (im *NativeImage) Image() image.Image

Image returns the wrapped image instance.

func (*NativeImage) Resize

func (im *NativeImage) Resize(w, h uint) error

Resize resizes the image to the given width and height.

func (*NativeImage) SetCompression

func (im *NativeImage) SetCompression(c ImageCompression) error

SetCompression sets the compression level of PNG encoding.

func (*NativeImage) SetFormat

func (im *NativeImage) SetFormat(f string) error

SetFormat sets the encoding format. When none is set, it will use the original format or fallback to JPEG.

func (*NativeImage) SetQuality

func (im *NativeImage) SetQuality(q uint8) error

SetQuality sets the quality of JEPG encoding.

func (*NativeImage) Width

func (im *NativeImage) Width() uint

Width returns the image width.

type SvgImage

type SvgImage struct {
	// contains filtered or unexported fields
}

SvgImage is the Image implementation for SVG images.

func NewSvgImage

func NewSvgImage(r io.Reader) (*SvgImage, error)

NewSvgImage returns an SvgImage instance.

func (*SvgImage) Clean

func (im *SvgImage) Clean() error

Clean sanitizes the SVG image by keeping only a specific set of tags and attributes.

func (*SvgImage) Close

func (im *SvgImage) Close() error

Close is a noop here.

func (*SvgImage) ContentType

func (im *SvgImage) ContentType() string

ContentType returns the image mimetype.

func (*SvgImage) Encode

func (im *SvgImage) Encode(w io.Writer) error

Encode encodes the image to an io.Writer.

func (*SvgImage) Format

func (im *SvgImage) Format() string

Format returns the image format.

func (*SvgImage) Gray16

func (im *SvgImage) Gray16() error

Gray16 is a noop here.

func (*SvgImage) Grayscale

func (im *SvgImage) Grayscale() error

Grayscale is a noop here.

func (*SvgImage) Height

func (im *SvgImage) Height() uint

Height returns the image height.

func (*SvgImage) Resize

func (im *SvgImage) Resize(w, h uint) error

Resize resizes the image to the given width and height.

func (*SvgImage) SetCompression

func (im *SvgImage) SetCompression(ImageCompression) error

SetCompression is a noop here.

func (*SvgImage) SetFormat

func (im *SvgImage) SetFormat(string) error

SetFormat is a noop here.

func (*SvgImage) SetQuality

func (im *SvgImage) SetQuality(uint8) error

SetQuality is a noop here.

func (*SvgImage) Width

func (im *SvgImage) Width() uint

Width returns the image width.

Directories

Path Synopsis
Package ico implements the .ico format decoding
Package ico implements the .ico format decoding

Jump to

Keyboard shortcuts

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