img

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

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

Go to latest
Published: Jan 8, 2026 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Separator = ` > `
)

Variables

This section is empty.

Functions

func DecodeConfig

func DecodeConfig(path string) (image.Config, error)

func Ext

func Ext(name string) (string, bool)

func HasChildren

func HasChildren(tag string) bool

func HasExt

func HasExt(name string) bool

func IsValidFormat

func IsValidFormat(name string) bool

func OpenAll

func OpenAll(files []string) ([]image.Image, error)

OpenAll loads images from files.

func Save

func Save(output string, base image.Image, opts ...EncodeOption) error

Save saves image according to the encoder https://github.com/sunshineplan/imgconv

func SaveAll

func SaveAll(output string, images []image.Image, opts ...EncodeOption) error

SaveAll saves images according to the encoder https://github.com/sunshineplan/imgconv

func SplitFunc

func SplitFunc(c rune) bool

func SplitTags

func SplitTags(tag string) []string

Types

type DecodeOption

type DecodeOption func(*Decoder)

func WithMeta

func WithMeta() DecodeOption

type Decoder

type Decoder struct {
	Fmt Format
	// contains filtered or unexported fields
}

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

func (*Decoder) Decode

func (dec *Decoder) Decode(f Format) (image.Image, error)

func (*Decoder) DecodeConfig

func (dec *Decoder) DecodeConfig(f Format) (image.Config, error)

func (*Decoder) DecodeXMP

func (dec *Decoder) DecodeXMP(r io.ReadSeeker) (xmp.XMP, error)

type EncodeOption

type EncodeOption func(*Encoder)

EncodeOption sets an optional parameter for the Encode and Save functions. https://github.com/disintegration/imaging

func BackgroundColor

func BackgroundColor(color color.Color) EncodeOption

BackgroundColor returns an EncodeOption that sets the background color.

func Base64

func Base64(outFmt Format) EncodeOption

Base64 returns an EncodeOption that encodes the format to Base64.

func GIFBackgroundIndex

func GIFBackgroundIndex(d byte) EncodeOption

GIFBackgroundIndex returns an EncodeOption that sets the delay for gif frames.

func GIFDelay

func GIFDelay(d int) EncodeOption

GIFDelay returns an EncodeOption that sets the delay for gif frames. This is a convenience function to set the same delay for all frames.

func GIFDelays

func GIFDelays(d []int) EncodeOption

GIFDelays returns an EncodeOption that sets the delay for gif frames.

func GIFDisposal

func GIFDisposal(d []byte) EncodeOption

GIFDisposal returns an EncodeOption that sets the delay for gif frames.

func GIFDrawer

func GIFDrawer(drawer draw.Drawer) EncodeOption

GIFDrawer returns an EncodeOption that sets the drawer that is used to convert the source image to the desired palette of the GIF-encoded image.

func GIFLoopCount

func GIFLoopCount(d int) EncodeOption

GIFLoopCount returns an EncodeOption that sets the delay for gif frames.

func GIFNumColors

func GIFNumColors(numColors int) EncodeOption

GIFNumColors returns an EncodeOption that sets the maximum number of colors used in the GIF-encoded image. It ranges from 1 to 256. Default is 256.

func GIFQuantizer

func GIFQuantizer(quantizer draw.Quantizer) EncodeOption

GIFQuantizer returns an EncodeOption that sets the quantizer that is used to produce a palette of the GIF-encoded image.

func PDFPages

func PDFPages(pages []image.Image) EncodeOption

PDFPages returns an EncodeOption that sets multiple pages for pdf conversion.

func PNGCompressionLevel

func PNGCompressionLevel(level png.CompressionLevel) EncodeOption

PNGCompressionLevel returns an EncodeOption that sets the compression level of the PNG-encoded image. Default is png.DefaultCompression.

func Padding

func Padding(padding string) EncodeOption

Padding returns an EncodeOption that writes a batch of images. Arguments are a list of images and a fmt string for zero padding: eg, %04d.

func Quality

func Quality(quality int) EncodeOption

Quality returns an EncodeOption that sets the output JPEG or PDF quality. Quality ranges from 1 to 100 inclusive, higher is better.

func TIFFCompressionType

func TIFFCompressionType(compressionType TIFFCompression) EncodeOption

TIFFCompressionType returns an EncodeOption that sets the compression type of the TIFF-encoded image. Default is tiff.Deflate.

func WEBPAnimationBackgroundColor

func WEBPAnimationBackgroundColor(color uint32) EncodeOption

WEBPAnimationBackgroundColor returns an EncodeOption that sets the webp animation durations. Canvas background color in BGRA order, used for clear operations.

func WEBPAnimationDisposal

func WEBPAnimationDisposal(disposal int) EncodeOption

WEBPAnimationDisposal returns an EncodeOption that sets the webp animation durations.

func WEBPAnimationDisposals

func WEBPAnimationDisposals(disposals []int) EncodeOption

WEBPAnimationDisposals returns an EncodeOption that sets the webp animation durations.

func WEBPAnimationDuration

func WEBPAnimationDuration(dur int) EncodeOption

WEBPAnimationDurations returns an EncodeOption that sets the webp animation durations.

func WEBPAnimationDurations

func WEBPAnimationDurations(dur []int) EncodeOption

WEBPAnimationDurations returns an EncodeOption that sets the webp animation durations.

func WEBPAnimationFrames

func WEBPAnimationFrames(frames []image.Image) EncodeOption

WEBPAnimationFrames returns an EncodeOption that sets the webp animation frames.

func WEBPAnimationLoopCount

func WEBPAnimationLoopCount(loops int) EncodeOption

WEBPAnimationLoopCount returns an EncodeOption that sets the webp animation durations.

func WEBPUseExtendedFormat

func WEBPUseExtendedFormat(b bool) EncodeOption

WEBPUseExtendedFormat returns EncodeOption that determines whether to use extended format of the WEBP-encoded image. Default is false.

type Encoder

type Encoder struct {
	Format       Format
	EncodeOption []EncodeOption

	Quality int
	// contains filtered or unexported fields
}

Encoder is format option

func NewEncoder

func NewEncoder(format Format, opts ...EncodeOption) *Encoder

NewEncoder initializes an encoder.

func (*Encoder) AnimateImages

func (enc *Encoder) AnimateImages(output string, images []image.Image) error

AnimateImages creates an animated WEBP according to the encoder

func (*Encoder) AnimatedGIF

func (enc *Encoder) AnimatedGIF(output string, images []string) error

func (*Encoder) AnimatedWEBP

func (enc *Encoder) AnimatedWEBP(output string, images []string) error

Animate creates an animated WEBP according to the encoder

func (*Encoder) Encode

func (enc *Encoder) Encode(w io.Writer, img image.Image) error

Encode writes the image img to w in the specified format (JPEG, PNG, GIF, TIFF, BMP, PDF, WEBP, HTML, or BASE64).

func (*Encoder) Save

func (enc *Encoder) Save(output string, base image.Image) error

Save saves image according to the encoder https://github.com/sunshineplan/imgconv

func (*Encoder) SaveAll

func (enc *Encoder) SaveAll(output string, images []image.Image) error

SaveAll saves images according to the encoder

type ExifField

type ExifField int
const (
	// title fields
	Title ExifField = iota
	Caption
	// creator fields
	Source
	Byline
	Credit
	Rights
	Copyright
	// caption fields
	UserComment
	Description
	Notes
	ImageDescription
	// tag fields
	CatalogSets
	HierarchicalSubject
	LastKeywordXMP
	Subject
	Keywords
	Categories
	TagsList
	// meta fields
	ImageHeight
	ImageWidth
	MIMEType
	FileTypeExtension
	WebP_Flags
	Duration
	FileName
	SourceFile
)

func (ExifField) IsHierarchical

func (f ExifField) IsHierarchical() bool

func (ExifField) Join

func (f ExifField) Join(t []string) string

func (ExifField) Sep

func (f ExifField) Sep() string

func (ExifField) Split

func (f ExifField) Split(tag string) []string

func (ExifField) String

func (i ExifField) String() string

type Format

type Format int

Format is an image file format.

const (
	JPEG Format = iota
	PNG
	GIF
	TIFF
	BMP
	PDF
	WEBP
	HTML
	BASE64
	URL
)

Image file formats.

func FormatFromExtension

func FormatFromExtension(ext string) (Format, error)

FormatFromExtension parses image format from filename extension: ".jpg" (or ".jpeg"), ".png", ".gif", ".tif" (or ".tiff"), ".bmp", ".pdf", ".b64 (or ".uue") and ".webp" are supported.

func FormatFromFilename

func FormatFromFilename(name string) (Format, error)

func (Format) Decode

func (f Format) Decode(r io.Reader) (image.Image, error)

func (Format) DecodeAnimatedWebP

func (f Format) DecodeAnimatedWebP(r io.Reader) (*webp.WEBP, error)

func (Format) DecodeConfig

func (f Format) DecodeConfig(r io.Reader) (image.Config, error)

func (Format) Encode

func (f Format) Encode(w io.Writer, img image.Image, opts ...EncodeOption) error

func (Format) ImageType

func (f Format) ImageType() imagetype.ImageType

func (Format) MarshalText

func (f Format) MarshalText() ([]byte, error)

func (Format) MimeType

func (f Format) MimeType() string

MimeType returns the mimetype of the image format.

func (Format) Save

func (f Format) Save(output string, img image.Image, opts ...EncodeOption) error

func (Format) SaveAll

func (f Format) SaveAll(output string, imgs []image.Image, opts ...EncodeOption) error

func (Format) String

func (f Format) String() (format string)

func (*Format) UnmarshalText

func (f *Format) UnmarshalText(text []byte) error

type Img

type Img struct {
	Fmt Format
	// contains filtered or unexported fields
}

func New

func New(name string) (*Img, error)

func Open

func Open(file string, withMeta bool) (*Img, error)

func (*Img) DublinCore

func (dec *Img) DublinCore() xmp.DublinCore

func (*Img) EncodeXMP

func (dec *Img) EncodeXMP(w io.Writer) error

func (*Img) Open

func (img *Img) Open() error

func (*Img) ReadMeta

func (img *Img) ReadMeta() error

func (*Img) Save

func (img *Img) Save(opts ...EncodeOption) error

func (*Img) SaveAs

func (img *Img) SaveAs(name string, opts ...EncodeOption) error

type TIFFCompression

type TIFFCompression int

TIFFCompression describes the type of compression used in Options.

const (
	TIFFUncompressed TIFFCompression = iota
	TIFFDeflate
)

Constants for supported TIFF compression types.

func (TIFFCompression) MarshalText

func (c TIFFCompression) MarshalText() (b []byte, err error)

func (*TIFFCompression) UnmarshalText

func (c *TIFFCompression) UnmarshalText(text []byte) error

type Tag

type Tag struct {
	Value    string `xml:",chardata"`
	Children []*Tag `xml:"Category"`
}

func FlatTags

func FlatTags(tags []string) []*Tag

func NewFlatTag

func NewFlatTag(val string) *Tag

type Tags

type Tags struct {
	XMLName  xml.Name `xml:"Categories"`
	Children []*Tag   `xml:"Category"`
}

func NewTags

func NewTags() *Tags

func UnmarshalHTags

func UnmarshalHTags(d []byte) (*Tags, error)

func (*Tags) IsEmpty

func (t *Tags) IsEmpty() bool

func (*Tags) StringSlice

func (t *Tags) StringSlice() []string

func (*Tags) UnmarshalXMP

func (t *Tags) UnmarshalXMP(d []byte) error

Directories

Path Synopsis
cmd
imgtag command
webp command

Jump to

Keyboard shortcuts

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