Documentation
¶
Overview ¶
package webpwrap provides a Go wrapper for the WebP image compression tools. It allows for easy conversion of images to WebP format with various options including quality control, cropping, and different input/output methods.
package webpwrap provides a Go wrapper for the WebP image compression tools. It allows for easy conversion of images to WebP format with various options including quality control, cropping, and different input/output methods.
package webpwrap provides a Go wrapper for the WebP image compression tools. It allows for easy conversion of images to WebP format with various options including quality control, cropping, and different input/output methods.
package webpwrap provides a Go wrapper for the WebP image compression tools. It allows for easy conversion of images to WebP format with various options including quality control, cropping, and different input/output methods.
Index ¶
- func Decode(r io.Reader) (image.Image, error)
- func DecodeWithContext(ctx context.Context, r io.Reader) (image.Image, error)
- func DetectUnsupportedPlatforms()
- func Encode(w io.Writer, m image.Image) error
- func EncodeWithContext(ctx context.Context, w io.Writer, m image.Image) error
- type CWebP
- func (c *CWebP) Crop(x, y, width, height int) *CWebP
- func (c *CWebP) Input(reader io.Reader) *CWebP
- func (c *CWebP) InputFile(file string) *CWebP
- func (c *CWebP) InputImage(img image.Image) *CWebP
- func (c *CWebP) Output(writer io.Writer) *CWebP
- func (c *CWebP) OutputFile(file string) *CWebP
- func (c *CWebP) Quality(quality uint) *CWebP
- func (c *CWebP) Reset() *CWebP
- func (c *CWebP) Run() error
- func (c *CWebP) RunWithContext(ctx context.Context) error
- func (c *CWebP) Version() (string, error)
- type DWebP
- func (c *DWebP) Input(reader io.Reader) *DWebP
- func (c *DWebP) InputFile(file string) *DWebP
- func (c *DWebP) Output(writer io.Writer) *DWebP
- func (c *DWebP) OutputFile(file string) *DWebP
- func (c *DWebP) Run() (image.Image, error)
- func (c *DWebP) RunWithContext(ctx context.Context) (image.Image, error)
- func (c *DWebP) Version() (string, error)
- type Encoder
- type OptionFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Decode ¶
Decode reads a WebP image from r and returns it as an image.Image. It is a convenience function that wraps the DWebP decoder.
Parameters:
- r: The io.Reader containing the WebP image data
Returns:
- image.Image: The decoded image
- error: Any error encountered during decoding
func DecodeWithContext ¶
DecodeWithContext reads a WebP image from r and returns it as an image.Image. The context can be used to cancel the operation. It is a convenience function that wraps the DWebP decoder.
Parameters:
- ctx: The context for cancellation
- r: The io.Reader containing the WebP image data
Returns:
- image.Image: The decoded image
- error: Any error encountered during decoding
func DetectUnsupportedPlatforms ¶
func DetectUnsupportedPlatforms()
func Encode ¶
Encode writes the Image m to w in WebP format using default settings. It is a convenience function that creates an Encoder with default quality (75). Any Image type may be encoded.
Parameters:
- w: The io.Writer to write the encoded WebP data
- m: The image.Image to encode
Returns:
- error: Any error encountered during encoding
func EncodeWithContext ¶
EncodeWithContext writes the Image m to w in WebP format using default settings and context support. The context can be used to cancel the operation. It is a convenience function that creates an Encoder with default quality (75). Any Image type may be encoded.
Parameters:
- ctx: The context for cancellation
- w: The io.Writer to write the encoded WebP data
- m: The image.Image to encode
Returns:
- error: Any error encountered during encoding
Types ¶
type CWebP ¶
type CWebP struct {
*binwrapper.BinWrapper
// contains filtered or unexported fields
}
CWebP wraps the cwebp command-line tool for compressing images to WebP format. It supports various input formats including PNG, JPEG, TIFF, WebP, and raw Y'CbCr samples. For more information, see: https://developers.google.com/speed/webp/docs/cwebp
func NewCWebP ¶
func NewCWebP(optionFuncs ...OptionFunc) *CWebP
NewCWebP creates a new CWebP instance with the given options. It initializes the binary wrapper and sets default values. The quality is set to -1 by default, which means the default cwebp quality will be used.
func (*CWebP) Crop ¶
Crop sets the cropping parameters for the source image. The cropping area must be fully contained within the source rectangle. Parameters:
- x: x-coordinate of the top-left corner
- y: y-coordinate of the top-left corner
- width: width of the crop area
- height: height of the crop area
Returns the CWebP instance for method chaining.
func (*CWebP) Input ¶
Input sets the reader to convert. Any previous calls to InputFile or InputImage will be ignored. Returns the CWebP instance for method chaining.
func (*CWebP) InputFile ¶
InputFile sets the input image file to convert. Any previous calls to Input or InputImage will be ignored. Returns the CWebP instance for method chaining.
func (*CWebP) InputImage ¶
InputImage sets the image to convert. Any previous calls to InputFile or Input will be ignored. Returns the CWebP instance for method chaining.
func (*CWebP) Output ¶
Output specifies the writer to write WebP file content. Any previous call to OutputFile will be ignored. Returns the CWebP instance for method chaining.
func (*CWebP) OutputFile ¶
OutputFile specifies the name of the output WebP file. Any previous call to Output will be ignored. Returns the CWebP instance for method chaining.
func (*CWebP) Quality ¶
Quality specifies the compression factor for RGB channels. The value must be between 0 and 100, where: - A small factor produces a smaller file with lower quality - A value of 100 achieves the best quality - The default is 75 Returns the CWebP instance for method chaining.
func (*CWebP) Reset ¶
Reset restores all parameters to their default values. Returns the CWebP instance for method chaining.
func (*CWebP) Run ¶
Run executes the cwebp command with the specified parameters. Returns an error if the command fails or if input/output is not properly configured.
func (*CWebP) RunWithContext ¶
RunWithContext executes the cwebp command with the specified parameters and context. The context can be used to cancel the operation. Returns an error if the command fails or if input/output is not properly configured.
type DWebP ¶
type DWebP struct {
*binwrapper.BinWrapper
// contains filtered or unexported fields
}
DWebP wraps the dwebp command-line tool for decompressing WebP files into PNG format. It provides various options for input/output handling and supports both file and stream-based operations. For more information, see: https://developers.google.com/speed/webp/docs/dwebp
func NewDWebP ¶
func NewDWebP(optionFuncs ...OptionFunc) *DWebP
NewDWebP creates a new DWebP instance with the given options. It initializes the binary wrapper and sets up the dwebp executable.
func (*DWebP) Input ¶
Input sets the reader to convert. Any previous calls to InputFile will be ignored. Returns the DWebP instance for method chaining.
func (*DWebP) InputFile ¶
InputFile sets the WebP file to convert. Any previous calls to Input will be ignored. Returns the DWebP instance for method chaining.
func (*DWebP) Output ¶
Output specifies the writer to write PNG file content. Any previous call to OutputFile will be ignored. Returns the DWebP instance for method chaining.
func (*DWebP) OutputFile ¶
OutputFile specifies the name of the output PNG file. Any previous call to Output will be ignored. Returns the DWebP instance for method chaining.
func (*DWebP) Run ¶
Run executes the dwebp command with the specified parameters. Returns the decoded image and any error encountered during the process. If no output is specified, returns the decoded image as an image.Image. If an output is specified (file or writer), returns nil, nil.
func (*DWebP) RunWithContext ¶
RunWithContext executes the dwebp command with the specified parameters and context. The context can be used to cancel the operation. Returns the decoded image and any error encountered during the process. If no output is specified, returns the decoded image as an image.Image. If an output is specified (file or writer), returns nil, nil.
type Encoder ¶
type Encoder struct {
// Quality specifies the compression factor for RGB channels.
// The value must be between 0 and 100, where:
// - A small factor produces a smaller file with lower quality
// - A value of 100 achieves the best quality
// - The default is 75
Quality uint
}
Encoder encodes image.Image into WebP format using cwebp. It provides control over the encoding quality and other parameters.
func (*Encoder) Encode ¶
Encode writes the Image m to w in WebP format. Any Image type may be encoded.
Parameters:
- w: The io.Writer to write the encoded WebP data
- m: The image.Image to encode
Returns:
- error: Any error encountered during encoding
func (*Encoder) EncodeWithContext ¶
EncodeWithContext writes the Image m to w in WebP format with context support. The context can be used to cancel the operation. Any Image type may be encoded.
Parameters:
- ctx: The context for cancellation
- w: The io.Writer to write the encoded WebP data
- m: The image.Image to encode
Returns:
- error: Any error encountered during encoding
type OptionFunc ¶
type OptionFunc func(binWrapper *binwrapper.BinWrapper) error
func SetSkipDownload ¶
func SetSkipDownload(isSkipDownload bool) OptionFunc
func SetVendorPath ¶
func SetVendorPath(path string) OptionFunc
