Documentation ¶
Overview ¶
Package imgdiet offers a simple and fast image processing and compression solution by leveraging C's [libvips] image processing library and its Go binding, [govips].
[libvips]: https://github.com/libvips/libvips [govips]: https://github.com/davidbyttow/govips
Index ¶
Constants ¶
const ( ErrOpenImage xerrors.Error = "failed to open image" ErrNilImage xerrors.Error = "image is nil" ErrInvalidResizeDimensions xerrors.Error = "dimensions must be greater than 0" )
const ( ImageTypeJPEG string = "JPEG" ImageTypePNG string = "PNG" ImageTypeGIF string = "GIF" )
List of image types supported by this package.
const ( LogLevelError = vips.LogLevelError LogLevelCritical = vips.LogLevelCritical LogLevelWarning = vips.LogLevelWarning LogLevelMessage = vips.LogLevelMessage LogLevelInfo = vips.LogLevelInfo LogLevelDebug = vips.LogLevelDebug )
List of libvips logging levels for convenience.
const ErrUnsupportedImageFormat xerrors.Error = "unsupported image format"
ErrUnsupportedImageFormat is returned when the image format is not supported by this package.
Variables ¶
This section is empty.
Functions ¶
func DefaultLogger ¶
DefaultLogger is a very simple logger the package uses by default. It complies with vips.LoggingHandlerFunction.
func DetectImageSize ¶
DetectImageSize takes an image as a byte array input and detects the image size in bytes.
func DetectImageType ¶
DetectImageType takes an image as a byte array input and detects its type based on its magic bytes. It returns a string representation of the image type and an error if the image type is not supported.
Types ¶
type Config ¶
type Config struct { // Logger defines the logger to be used by libvips. Logger func(domain string, verbosity vips.LogLevel, message string) // LogLevel is the level of logging to be used by libvips. LogLevel vips.LogLevel // Cache defines the size of the libvips cache in bytes. Cache int // MaxConcurrency defines the maximum number of concurrent operations that // libvips can perform. MaxConcurrency int // ReportLeaks defines whether libvips should report memory leaks. ReportLeaks bool }
Config defines the configuration for the libvips library.
func DefaultConfig ¶
func DefaultConfig() *Config
DefaultConfig returns a set of opinionated and sane defaults for the libvips library.
type Image ¶
type Image struct {
// contains filtered or unexported fields
}
Image defines an image to be optimized and manages its lifecycle.
func (*Image) Close ¶
func (i *Image) Close()
Close releases the resources associated with the Image.
func (*Image) Optimize ¶
Optimize takes the given Options and optimizes the image accordingly. It returns the optimized image as a byte slice or an error if the optimization fails.
func (*Image) Resize ¶
Resize takes a set of dimensions and resizes the image to those dimensions. If opts is not nil, the resulting image is optimized according to the given Options.
type Options ¶
type Options struct { // Quality defines the quality of the output image. It is a number between 0 // and 100. Quality int // Compression defines the compression level of the output image. It is a // number between 0 and 9. // // Only valid for PNG images. Compression int // Effort defines the level of CPU effort to be used when optimizing the // output image. It is a number between 0 and 9. // // Only valid for GIF images. Effort int // QuantTable defines the quantization table to be used for the output // image. It is a number between 0 and 8. // // Only valid for JPEG images. QuantTable int // Bitdepth defines the number of bits per pixel of the output image. It is // a number between 1 and 8. // // Only valid for GIF and PNG images. Bitdepth int // Dither defines the amount of dithering to be applied during 8bpp (bits // per pixel) quantization. It is a floating-point number between 0 and 1. // // Only valid for GIF and PNG images. Dither float64 // OptimizeCoding defines whether the output image should have its coding // optimized. // // Only valid for JPEG images. OptimizeCoding bool // Interlaced defines whether the output image should be interlaced. Interlaced bool // StripMetadata defines whether the output image should have its metadata // stripped. StripMetadata bool // OptimizeICCProfile defines whether the output image should have its ICC // profile optimized. OptimizeICCProfile bool // TrellisQuant defines whether the output image should have its // quantization tables optimized using trellis quantization. // // Only valid for JPEG images. TrellisQuant bool // OvershootDeringing defines whether the output image should have its // quantization tables optimized using overshoot deringing. // // Only valid for JPEG images. OvershootDeringing bool // OptimizeScans defines whether the output image should have its scans // optimized. // // Only valid for JPEG images. OptimizeScans bool }
Options represents the parameters used to optimize an image.
func DefaultOptions ¶
func DefaultOptions() *Options
DefaultOptions returns a set of opinionated defaults for optimizing images.
Directories ¶
Path | Synopsis |
---|---|
cmd
|
|
imgdiet/internal/app
Package app is the main package for the application.
|
Package app is the main package for the application. |
imgdiet/internal/meta
Package meta provides build information and other metadata for the application.
|
Package meta provides build information and other metadata for the application. |