Documentation
¶
Index ¶
- Constants
- Variables
- func AddBackgroundColor(img image.Image, clr color.Color) draw.Image
- func AddBackgroundWhite(img image.Image) image.Image
- func AddBorder(img draw.Image, clr color.Color, width int) draw.Image
- func AddBorderAverageColor(img image.Image, width int) image.Image
- func Aspect(width, height int) float64
- func Bleach(img image.Image) image.Image
- func BuildGIFAnimationSimple(src *gif.GIF, delay int, imgs []image.Image, f ToPalettedFunc) *gif.GIF
- func BuildGIFAnimationSimpleRead(src *gif.GIF, delay int, names []string, f ToPalettedFunc, consistentSize bool) (*gif.GIF, error)
- func ColsFilteredColor(img image.Image, c ...color.Color) []int
- func Crop(src image.Image, retain image.Rectangle) image.Image
- func CropPadding(src image.Image, isPadding padding.IsPaddingFunc, retainPaddingWidth uint32) image.Image
- func CropX(src image.Image, width int, align string) image.Image
- func CropY(src image.Image, height int, align string) image.Image
- func DecodeBytes(data []byte) (image.Image, string, error)
- func DecodeConfigFile(filename string) (image.Config, string, error)
- func DecodeWebP(r io.Reader) (image.Image, string, error)
- func EncodeJPEGWithExif(w io.Writer, img image.Image, opts *jpeg.Options, exif []byte) error
- func GammaCorrect(src image.Image, gamma float64) *image.RGBA
- func ImageAspect(img image.Image) float64
- func ImageToPaletted(src image.Image, p color.Palette) *image.Paletted
- func ImageToPalettedPlan9(src image.Image) *image.Paletted
- func ImageToPalettedWebSafe(src image.Image) *image.Paletted
- func ImageToRGBA(src image.Image) *image.RGBA
- func IsImageExt(imagePath string) bool
- func IsNilOrEmpty(img image.Image) bool
- func JPEGMarker(b byte) []byte
- func MergeXRGBA(imgs []image.Image) image.Image
- func MergeXSameY(images []image.Image, larger bool) image.Image
- func MergeXSameYRead(locations []string, larger bool) (image.Image, error)
- func MergeYSameX(images []image.Image, larger bool) image.Image
- func MergeYSameXRead(locations []string, larger bool) (image.Image, error)
- func NewRGBAColor(rect image.Rectangle, clr color.RGBA) *image.RGBA
- func NewRGBATransparent(rect image.Rectangle) *image.RGBA
- func NewRGBAWhite(rect image.Rectangle) *image.RGBA
- func Overlay(src, overlay image.Image, offset image.Point) image.Image
- func OverlayMore(src, overlay image.Image, overlayLocation string, padX, padY int) image.Image
- func OverlayOffset(src, overlay image.Rectangle, overlayLocation string, padX, padY int) image.Point
- func PaintBorder(img draw.Image, clr color.Color, width int)
- func PaintColor(img draw.Image, clr color.Color, area image.Rectangle)
- func ParseScaler(rawInterpolation string) (draw.Scaler, error)
- func ReadDirJPEGFiles(dir string, rx *regexp.Regexp) (osutil.DirEntries, error)
- func ReadImage(location string) (image.Image, string, error)
- func ReadImageFile(filename string) (image.Image, string, error)
- func ReadImageHTTP(imageURL string) (image.Image, string, error)
- func ReadImages(locations []string) ([]image.Image, error)
- func RectangleBorderXMax(rect image.Rectangle, pixels int) image.Rectangle
- func RectangleBorderXMin(rect image.Rectangle, pixels int) image.Rectangle
- func RectangleBorderYMax(rect image.Rectangle, pixels int) image.Rectangle
- func RectangleBorderYMin(rect image.Rectangle, pixels int) image.Rectangle
- func RectanglePixelCount(r image.Rectangle) int
- func Resize(width, height int, src image.Image, scale draw.Scaler) image.Image
- func ResizeMax(maxWidth, maxHeight int, src image.Image, scale draw.Scaler) image.Image
- func ResizeMaxDimension(maxDimension int, src image.Image, scale draw.Scaler) image.Image
- func ResizeMin(minWidth, minHeight int, src image.Image, scale draw.Scaler) image.Image
- func ResizePathJPEG(src, out string, x, y int, o *JPEGEncodeOptions) error
- func ResizePathJPEGDir(src, out string, x, y int, o *JPEGEncodeOptions) error
- func ResizePathJPEGFile(src, out string, x, y int, o *JPEGEncodeOptions) error
- func ResizeSameX(images []image.Image, larger bool) []image.Image
- func ResizeSameY(images []image.Image, larger bool) []image.Image
- func RowsFilteredColor(img image.Image, c color.Color, cmore ...color.Color) []int
- func Scale(src image.Image, rect image.Rectangle, scale draw.Scaler) image.Image
- func ScalerBest() draw.Scaler
- func ScalerDefault() draw.Scaler
- func SliceXY(images []image.Image, maxIdx int) (minX, maxX, minY, maxY, sumX, sumY int)
- func WriteGIFFile(filename string, img *gif.GIF, perm os.FileMode) (err error)
- type Image
- func (im Image) GIF() (*gif.GIF, error)
- func (im Image) GIFBytes() ([]byte, error)
- func (im Image) JPEGBytes(opt *JPEGEncodeOptions) ([]byte, error)
- func (im Image) PNGBytes() ([]byte, error)
- func (im Image) Paletted() (*image.Paletted, error)
- func (im Image) SplitHorz(sqLarger bool, bgcolor color.Color) (imgLeft, imgRight image.Image, err error)
- func (im Image) SquareLarger(bgcolor color.Color) image.Image
- func (im Image) SquareSmaller() image.Image
- func (im Image) WriteGIFFile(filename string) (err error)
- func (im Image) WriteJPEG(w io.Writer, opt *JPEGEncodeOptions) error
- func (im Image) WriteJPEGFile(filename string, opt *JPEGEncodeOptions) error
- func (im Image) WriteJPEGFileSimple(filename string, quality int) error
- func (im Image) WriteJPEGResponseWriter(w http.ResponseWriter, addContentTypeHeader bool, opt *JPEGEncodeOptions) error
- func (im Image) WritePNG(w io.Writer) error
- func (im Image) WritePNGFile(filename string) error
- func (im Image) WritePNGResponseWriter(w http.ResponseWriter, addContentTypeHeader bool) error
- type ImageMeta
- type ImageMetaSet
- func (ims *ImageMetaSet) CloseFilesAll() error
- func (ims *ImageMetaSet) Images() []image.Image
- func (ims *ImageMetaSet) MaxX() int
- func (ims *ImageMetaSet) MaxY() int
- func (ims *ImageMetaSet) Stats() ImagesStats
- func (ims *ImageMetaSet) SumX(maxIndexInclusive int) int
- func (ims *ImageMetaSet) SumY(maxIndexInclusive int) int
- type ImageMetadata
- type Images
- func (imgs Images) ConsistentSize(scale draw.Scaler, yAlign string)
- func (imgs Images) Dimensions() []image.Point
- func (imgs Images) DxMax() int
- func (imgs Images) DxMin() int
- func (imgs Images) DxSum(maxIndexInclusive int) int
- func (imgs Images) Dxs() []int
- func (imgs Images) DyMax() int
- func (imgs Images) DyMin() int
- func (imgs Images) DySum(maxIndexInclusive int) int
- func (imgs Images) Dys() []int
- func (imgs Images) Stats() ImagesStats
- type ImagesStats
- type JPEGEncodeOptions
- type Matrix
- func (matrix Matrix) AddBackgroundColor(clr color.Color)
- func (matrix Matrix) AddBackgroundColorHex(hexcolor string) error
- func (matrix Matrix) Dimensions() [][]image.Point
- func (matrix Matrix) DxSumMax() int
- func (matrix Matrix) DxSumMin() int
- func (matrix Matrix) Merge(largerX, largerY bool) image.Image
- type SOIFilterWriter
- type ToPalettedFunc
Constants ¶
const ( AlignTop = "top" AlignCenter = "center" AlignBottom = "bottom" AlignLeft = "left" AlignRight = "right" )
const ( AlgNearestNeighbor = "nearestneighbor" AlgApproxBiLinear = "approxbilinear" AlgBiLinear = "bilinear" AlgCatmullRom = "catmullrom" )
const ( LocUpper = "upper" LocMiddle = "middle" LocLower = "lower" LocLeft = "left" LocCenter = "center" LocRight = "right" LocUpperLeft = "upperleft" LocUpperRight = "upperright" LocLowerLeft = "lowerleft" LocLowerRight = "lowerright" )
const ( FileExtensionWebp = ".webp" FormatNameJPG = "jpeg" FormatNamePNG = "png" FormatNameWEBP = "webp" )
const ( JPEGExt = ".jpeg" JPEGExtJPG = ".jpg" JPEGQualityDefault = jpeg.DefaultQuality // 75 JPEGQualityMax = 100 JPEGQualityMin = 1 JPEGMarkerPrefix = 0xff JPEGMarkerExif = 0xe1 JPEGMarkerSOI = 0xd8 )
Variables ¶
var ( ErrImageNotSet = errors.New("image not set") ErrWriterNotSet = errors.New("writer not set") )
var ( ErrSrcDirNotDefined = errors.New("source directory not defined") ErrOutDirNotDefined = errors.New("output directory not defined") ErrSrcDirNotDir = errors.New("source directory is not a directory") ErrOutDirNotDir = errors.New("output directory is not a directory") )
var JPEGEncodeOptionsQualityMax = &JPEGEncodeOptions{ Options: &jpeg.Options{ Quality: JPEGQualityMax}}
var RxFileExtensionJPG = regexp.MustCompile(`(?i)^.*\.*jpe?g$`)
Functions ¶
func AddBackgroundColor ¶
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`. This returns a `draw.Image` so it can be used as an input to `draw.Draw()`.
func AddBackgroundWhite ¶
AddBackgroundWhite adds a white background which is usable when the image has a transparent background.
func AddBorder ¶ added in v0.35.7
AddBorder adds a border to a `draw.Image`. If you have an `image.Image`, first convert it with `ImageToRGBA(img)`.
func AddBorderAverageColor ¶ added in v0.49.0
func BuildGIFAnimationSimple ¶ added in v0.70.12
func BuildGIFAnimationSimple(src *gif.GIF, delay int, imgs []image.Image, f ToPalettedFunc) *gif.GIF
BuildGifAnimationSimple assembles a set of images in an animated GIF file. Set `delay` to `0`.
func BuildGIFAnimationSimpleRead ¶ added in v0.70.12
func ColsFilteredColor ¶ added in v0.33.3
func CropPadding ¶ added in v0.64.6
func DecodeBytes ¶ added in v0.51.0
DecodeBytes wraps Decode which decodes an image that has been encoded in a registered format. The string returned is the format name used during format registration. Format registration is typically done by an init function in the codec- specific package.
func DecodeConfigFile ¶ added in v0.64.0
func EncodeJPEGWithExif ¶ added in v0.69.2
EncodeJPEGWithExif encodes a JPEG image, inserts Exif data after the SOI marker, and writes to w.
func ImageAspect ¶
func ImageToPaletted ¶ added in v0.36.0
ImageToPaletted is used for GIF conversion.
func ImageToPalettedPlan9 ¶ added in v0.36.0
ImageToPalettedPlan9 converts an image to `*image.Paletted`. See the go implementation here: https://github.com/golang/go/blob/master/src/image/gif/writer.go
func ImageToPalettedWebSafe ¶ added in v0.36.5
ImageToPalettedWebSafe uses the 216 color palette created by Netscape. This is only necessary for legacy/old applications. See more here: https://en.wikipedia.org/wiki/Web_colors#Web-safe_colors
func IsImageExt ¶
func IsNilOrEmpty ¶
func JPEGMarker ¶ added in v0.49.0
func MergeXRGBA ¶ added in v0.36.5
MergeXRGBA 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 OverlayMore ¶ added in v0.35.6
func OverlayOffset ¶ added in v0.35.7
func PaintBorder ¶ added in v0.35.7
PaintBorder colorizes a border of size `width` in the existing canvas, overwriting any colors in that space.
func PaintColor ¶ added in v0.35.7
func ReadDirJPEGFiles ¶ added in v0.49.0
func ReadImageHTTP ¶ added in v0.37.1
func RectangleBorderXMax ¶
func RectangleBorderXMin ¶
func RectangleBorderYMax ¶
func RectangleBorderYMin ¶
func RectanglePixelCount ¶ added in v0.35.1
func Resize ¶
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 ResizeMax ¶
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 ¶
ResizeMaxDimension resizes an image so that the max dimension matches what is supplied. If `maxDimension` is `0` or less a zero value `image.Image` is returned.
func ResizeMin ¶
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 ResizePathJPEG ¶ added in v0.51.0
func ResizePathJPEG(src, out string, x, y int, o *JPEGEncodeOptions) error
func ResizePathJPEGDir ¶ added in v0.51.0
func ResizePathJPEGDir(src, out string, x, y int, o *JPEGEncodeOptions) error
func ResizePathJPEGFile ¶ added in v0.51.0
func ResizePathJPEGFile(src, out string, x, y int, o *JPEGEncodeOptions) error
func RowsFilteredColor ¶ added in v0.33.2
func Scale ¶
Scale will resize the image to the provided rectangle using the provided interpolation function.
func ScalerBest ¶
func ScalerDefault ¶
ScalerDefault returns a general best results interpolation algorithm. See more here https://blog.codinghorror.com/better-image-resizing/ , https://support.esri.com/en/technical-article/000005606 , https://stackoverflow.com/questions/384991/what-is-the-best-image-downscaling-algorithm-quality-wise/6171860 .
Types ¶
type Image ¶ added in v0.51.0
func (Image) JPEGBytes ¶ added in v0.70.8
func (im Image) JPEGBytes(opt *JPEGEncodeOptions) ([]byte, error)
func (Image) SquareLarger ¶ added in v0.64.6
SquareLarger returns a square image that is cropped to where the height and weight are equal to the larger of the source image. Additional padding is added, if necessary.
func (Image) SquareSmaller ¶ added in v0.64.6
SquareSmaller returns a square image that is cropped to where the height and weight are equal to the smaller of the source image. Source image pixes may be cropped and no additional pixels are added.
func (Image) WriteGIFFile ¶ added in v0.70.8
func (Image) WriteJPEG ¶ added in v0.51.0
func (im Image) WriteJPEG(w io.Writer, opt *JPEGEncodeOptions) error
func (Image) WriteJPEGFile ¶ added in v0.51.0
func (im Image) WriteJPEGFile(filename string, opt *JPEGEncodeOptions) error
func (Image) WriteJPEGFileSimple ¶ added in v0.63.11
func (Image) WriteJPEGResponseWriter ¶ added in v0.51.0
func (im Image) WriteJPEGResponseWriter(w http.ResponseWriter, addContentTypeHeader bool, opt *JPEGEncodeOptions) error
func (Image) WritePNGFile ¶ added in v0.51.0
func (Image) WritePNGResponseWriter ¶ added in v0.51.0
func (im Image) WritePNGResponseWriter(w http.ResponseWriter, addContentTypeHeader bool) error
type ImageMeta ¶
func NewImageMeta ¶ added in v0.35.0
func (*ImageMeta) ColorAverage ¶ added in v0.33.2
func (*ImageMeta) ColorsHistogram ¶ added in v0.64.6
func (*ImageMeta) ColorsMatrix ¶ added in v0.64.6
ColorsMatrix returns colors for an image covering the pixels described in `image.Rectangle`: https://pkg.go.dev/image#Rectangle
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) Images ¶ added in v0.37.8
func (ims *ImageMetaSet) Images() []image.Image
func (*ImageMetaSet) MaxX ¶
func (ims *ImageMetaSet) MaxX() int
func (*ImageMetaSet) MaxY ¶
func (ims *ImageMetaSet) MaxY() int
func (*ImageMetaSet) Stats ¶
func (ims *ImageMetaSet) Stats() ImagesStats
func (*ImageMetaSet) SumX ¶
func (ims *ImageMetaSet) SumX(maxIndexInclusive int) int
func (*ImageMetaSet) SumY ¶
func (ims *ImageMetaSet) SumY(maxIndexInclusive int) int
type ImageMetadata ¶ added in v0.64.5
func NewImageMetadata ¶ added in v0.64.5
func NewImageMetadata(img image.Image) ImageMetadata
type Images ¶ added in v0.36.5
func (Images) ConsistentSize ¶ added in v0.36.5
ConsistentSize resizes and crops the images so that they have all the same size. It prioritize resizing images to max Dx and then cropping Dy so they are consistent.
func (Images) Dimensions ¶ added in v0.37.8
func (Images) DxSum ¶ added in v0.36.5
DxSum returns the sum of widths up to and including `maxIndexInclusive`. Use a negative value for `maxIndexInclusive` to include all elements.
func (Images) DySum ¶ added in v0.36.5
DySum returns the sum of heights up to and including `maxIndexInclusive`. Use a negative value for `maxIndexInclusive` to include all elements.
func (Images) Stats ¶ added in v0.36.5
func (imgs Images) Stats() ImagesStats
type ImagesStats ¶ added in v0.36.5
type JPEGEncodeOptions ¶ added in v0.49.0
type JPEGEncodeOptions struct {
Options *jpeg.Options
Exif []byte
ReadFilenameRegexp *regexp.Regexp
WriteExtension string
}
func (JPEGEncodeOptions) ReadFilenameRegexpOrDefault ¶ added in v0.49.0
func (opts JPEGEncodeOptions) ReadFilenameRegexpOrDefault() *regexp.Regexp
func (JPEGEncodeOptions) WriteExtensionOrDefault ¶ added in v0.49.0
func (opts JPEGEncodeOptions) WriteExtensionOrDefault() string
type Matrix ¶
func MatrixRead ¶
func (Matrix) AddBackgroundColor ¶
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) Dimensions ¶ added in v0.37.8
type SOIFilterWriter ¶ added in v0.69.2
type SOIFilterWriter struct {
// contains filtered or unexported fields
}
SOIFilterWriter is a writer that filters out the SOI marker (0xFF 0xD8) from JPEG data.
func NewSOIFilterWriter ¶ added in v0.69.2
func NewSOIFilterWriter(w io.Writer) *SOIFilterWriter
func (*SOIFilterWriter) Close ¶ added in v0.69.2
func (s *SOIFilterWriter) Close() error
Close implements io.Closer