Documentation ¶
Index ¶
- Constants
- Variables
- type ImageMagick
- func (p *ImageMagick) FitToSize(config *img.TransformationConfig) (*img.Image, error)
- func (p *ImageMagick) LoadImageInfo(src *img.Image) (*img.Info, error)
- func (p *ImageMagick) Optimise(config *img.TransformationConfig) (*img.Image, error)
- func (p *ImageMagick) Resize(config *img.TransformationConfig) (*img.Image, error)
Constants ¶
const ( MaxWebpWidth = 16383 MaxWebpHeight = 16383 // MaxAVIFTargetSize is a maximum size in pixels of the result image // that could be converted to AVIF. // // This is mainly done because encoding to AVIF consumes a lot of memory, and CPU time MaxAVIFTargetSize = 2000 * 2000 MaxJxlLossyTargetSize = 1000 * 1000 JxlMime = "image/jxl" WebpMime = "image/webp" AvifMime = "image/avif" )
Variables ¶
var Debug = true
Debug is a flag for logging. When true, all IM commands will be printed to stdout.
Functions ¶
This section is empty.
Types ¶
type ImageMagick ¶
type ImageMagick struct { // AdditionalArgs are static arguments that will be passed to ImageMagick "convert" command for all operations. // Argument name and value should be in separate array elements. AdditionalArgs []string // GetAdditionalArgs could return additional arguments for ImageMagick "convert" command. // "op" is the name of the operation: "optimise", "resize" or "fit". // Some fields in the target info might not be filled, so you need to check on them! // Argument name and value should be in a separate array elements. GetAdditionalArgs func(op string, image []byte, source *img.Info, target *img.Info) []string // contains filtered or unexported fields }
func NewImageMagick ¶
func NewImageMagick(im string, idi string) (*ImageMagick, error)
NewImageMagick creates a new ImageMagick processor. It does require ImageMagick binaries to be installed on the local machine.
im is a path to ImageMagick "convert" binary. idi is a path to ImageMagick "identify" binary.
func (*ImageMagick) FitToSize ¶
func (p *ImageMagick) FitToSize(config *img.TransformationConfig) (*img.Image, error)
FitToSize resizes input image to exact size with cropping everything that out of the bound. It doesn't respect the aspect ratio of the original image.
Format of the size argument is WIDTHxHEIGHT, e.g. 300x200. Both dimensions must be included.
func (*ImageMagick) LoadImageInfo ¶ added in v8.6.0
func (*ImageMagick) Optimise ¶
func (p *ImageMagick) Optimise(config *img.TransformationConfig) (*img.Image, error)
func (*ImageMagick) Resize ¶
func (p *ImageMagick) Resize(config *img.TransformationConfig) (*img.Image, error)
Resize resizes an image to the given size preserving aspect ratio. No cropping applies.
Format of the size argument is WIDTHxHEIGHT with any of the dimension could be dropped, e.g. 300, x200, 300x200.