Documentation
¶
Index ¶
- Constants
- type Image
- func (i *Image) AddArguments(args map[string]any) *Image
- func (i *Image) CropImage(w, h, x, y int, pos ...PositionType) *Image
- func (i *Image) CropThumbnailImage(w, h int) *Image
- func (i *Image) DropFrames() *Image
- func (i *Image) ExtentImage(w, h, x, y int, pos ...PositionType) *Image
- func (i *Image) FlipImage() *Image
- func (i *Image) FlopImage() *Image
- func (i *Image) GetAspectRatio() float64
- func (i *Image) GetFrames() int
- func (i *Image) GetHeight() int
- func (i *Image) GetWidth() int
- func (i *Image) PreserveEXIF() *Image
- func (i *Image) ResizeImage(w, h int, typ ...ResizeType) *Image
- func (i *Image) RotateImage(degree int) *Image
- func (i *Image) SetBackgroundColor(color string) *Image
- func (i *Image) SetImageFormat(format ImageFormat) *Image
- func (i *Image) SetImageFramerate(fps int) *Image
- func (i *Image) SetLoop(count int) *Image
- func (i *Image) SetQuality(quality int) *Image
- func (i *Image) ThumbnailImage(w, h int) *Image
- func (i *Image) WriteImage(path string) error
- type ImageFormat
- type Output
- type PositionType
- type ResizeType
Constants ¶
const ( ImageFormatUnknown = "" ImageFormatJPEG = "jpg" ImageFormatJPEGXL = "jxl" ImageFormatWEBP = "webp" ImageFormatPNG = "png" ImageFormatAVIF = "avif" ImageFormatAPNG = "apng" ImageFormatBMP = "bmp" ImageFormatGIF = "gif" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Image ¶
type Image struct {
Stream *ffprobe.Stream
Width int
Height int
Path string
Output *Output
Silent bool
// contains filtered or unexported fields
}
Image
func NewImageFromBytes ¶ added in v1.0.5
func (*Image) AddArguments ¶ added in v1.0.6
AddArguments adds custom ffmpeg arguments to the output.
func (*Image) CropImage ¶
func (i *Image) CropImage(w, h, x, y int, pos ...PositionType) *Image
CropImage extracts a region of the image.
If "pos" is specified, "x" and "y" should be kept as 0.
func (*Image) CropThumbnailImage ¶
CropThumbnailImage creates a fixed size thumbnail by first scaling the image up or down and cropping a specified area from the center.
func (*Image) DropFrames ¶ added in v1.0.1
DropFrames makes any animated images to static image by specifing `-vframes 1`.
func (*Image) ExtentImage ¶
func (i *Image) ExtentImage(w, h, x, y int, pos ...PositionType) *Image
ExtentImage comfortability method for setting image size. The method sets the image size and allows setting x,y coordinates where the new area begins.
If "pos" is specified, "x" and "y" should be kept as 0.
func (*Image) GetAspectRatio ¶
GetAspectRatio returns the aspect ratio of the image (w / h).
func (*Image) GetFrames ¶ added in v1.0.1
GetFrames returns the frame count of the image, returns 0 if it's not an animated image.
func (*Image) PreserveEXIF ¶
PreserveEXIF preserves the metadata from the image, the metadata might contains GPS location or sensitive data, be caution.
NOTE: Requires exiftool to be installed. The function does nothing if "exiftool" command was not found.
func (*Image) ResizeImage ¶
func (i *Image) ResizeImage(w, h int, typ ...ResizeType) *Image
ResizeImage scales the size of an image to the given dimensions. The other parameter will be calculated if 0 is passed as either param. If ResizeType parameter is used both width and height must be given. The image will be stretched to exact size if ResizeType was left unspecified.
- ResizeTypeUpscale: Given dimensions 400x400 an image of dimensions 300x225 would be scaled up to size 533x400.
- ResizeTypeDownscale: Given dimensions 400x400 an image of dimensions 300x225 would be scaled up to size 400x300.
func (*Image) RotateImage ¶
RotateImage rotates an image the specified number of degrees. Empty triangles left over from rotating the image are filled with the background color (black as default, can be set with SetBackgroundColor).
func (*Image) SetBackgroundColor ¶
SetBackgroundColor sets the object's default background color. Colors can be a name, hex, e.g. "black", "#FFFFFF", "0xFFFFFF" or rgba "#00000000".
func (*Image) SetImageFormat ¶
func (i *Image) SetImageFormat(format ImageFormat) *Image
SetImageFormat sets the output format and automatically decides the codec. Format will be detect automatically from the output filename if it wasn't been setted.
func (*Image) SetImageFramerate ¶
SetImageFramerate changes the fps of the image, remains unchanged if the target fps is higher than current framerates. Filesize will be reduced if lower framerate was setted.
func (*Image) SetLoop ¶
SetLoop sets the repeat setting for animated image (e.g. GIF, WebP). - "-1" = no loop - "0" = infinite - "1" = loop once (play 2 times) - "2" = loop twice (play 3 times) - etc
func (*Image) SetQuality ¶
SetQuality sets the quality for the image from 1 (low quality) to 100 (high quality). Native ffmpeg only works for: AVIF, JPEG, JPEGXL, WEBP.
NOTE: for output format as PNG, the pngquant is required to be installed. The function does nothing for PNG if "pngquant" command was not found.
NOTE: for output format as GIF, the gifsicle is required to be installed. The function does nothing for GIF if "gifsicle" command was not found.
func (*Image) ThumbnailImage ¶
ThumbnailImage creates a fixed size thumbnail and centered the image, the extented area will be filled with background color (black as default, can be set with SetBackgroundColor).
func (*Image) WriteImage ¶
WriteImage writes an image to the specified filename. If the filename parameter is empty string, the image is written to the source file.
type PositionType ¶
type PositionType string
PositionType
const ( PositionTypeNone PositionType = "" PositionTypeTopLeft PositionType = "top_left" PositionTypeTop PositionType = "top" PositionTypeTopRight PositionType = "top_right" PositionTypeLeft PositionType = "left" PositionTypeCenter PositionType = "center" PositionTypeRight PositionType = "right" PositionTypeBottomLeft PositionType = "bottom_left" PositionTypeBottom PositionType = "bottom" PositionTypeBottomRight PositionType = "bottom_right" )
type ResizeType ¶
type ResizeType int
ResizeType
const ( ResizeTypeNone ResizeType = iota ResizeTypeUpscale ResizeTypeDownscale )




































