### AdjustBrightness usage examples Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/adjust.md Examples showing how to increase or decrease image brightness. ```go dst := imaging.AdjustBrightness(src, 10) // brighter dst := imaging.AdjustBrightness(src, -10) // darker ``` -------------------------------- ### FormatFromExtension usage examples Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/io.md Examples showing successful format parsing and handling of unsupported extensions. ```go f, err := imaging.FormatFromExtension(".PNG") if err != nil { log.Fatalf("unsupported format: %v", err) } // f == imaging.PNG f, err := imaging.FormatFromExtension(".unsupportedextension") if err != imaging.ErrUnsupportedFormat { ... } ``` -------------------------------- ### AdjustContrast usage examples Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/adjust.md Examples showing how to increase contrast by 20% and decrease it by 10%. ```go // Increase contrast by 20%. dst := imaging.AdjustContrast(src, 20) // Decrease contrast by 10%. dst := imaging.AdjustContrast(src, -10) ``` -------------------------------- ### Blur usage examples Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/effects.md Examples demonstrating light, strong, and zero-sigma blur applications. ```go // Light blur. dst := imaging.Blur(src, 0.5) // Strong blur. dst := imaging.Blur(src, 3.5) // sigma <= 0 returns a clone — no error. dst := imaging.Blur(src, 0) ``` -------------------------------- ### Using Format.String method Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/io.md Example of calling String on a Format constant to get its name. ```go imaging.JPEG.String() // "JPEG" ``` -------------------------------- ### Sharpen usage examples Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/effects.md Examples demonstrating moderate, strong, and negative-sigma sharpen applications. ```go // Moderate sharpening. dst := imaging.Sharpen(src, 0.5) // Strong sharpening. dst := imaging.Sharpen(src, 1.5) // sigma <= 0 yields an unmodified clone. dst := imaging.Sharpen(src, -1) ``` -------------------------------- ### AdjustGamma usage example Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/adjust.md Example showing how to darken an image using AdjustGamma. ```go // Darken the image. dst := imaging.AdjustGamma(src, 0.75) ``` -------------------------------- ### CropCenter usage example Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/compositing.md Example of calling CropCenter to create a 200x200 crop from the center of a source image. ```go dst := imaging.CropCenter(src, 200, 200) ``` -------------------------------- ### Open function signature and usage examples Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/io.md Shows the Open function signature and two usage examples: loading an image from a file, and loading with AutoOrientation option. ```go // io.go:95 // Open loads an image from file. // // Examples: // // // Load an image from file. // img, err := imaging.Open("test.jpg") // // // Load an image and transform it depending on the EXIF orientation tag (if present). // img, err := imaging.Open("test.jpg", imaging.AutoOrientation(true)) // func Open(filename string, opts ...DecodeOption) (image.Image, error) ``` -------------------------------- ### New function usage examples Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/compositing.md Examples of creating a transparent canvas and an opaque white canvas using the New function. ```go // A 400x400 transparent canvas. dst := imaging.New(400, 400, color.NRGBA{0, 0, 0, 0}) // An opaque white 100x100 canvas. dst := imaging.New(100, 100, color.White) ``` -------------------------------- ### OverlayCenter usage example Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/compositing.md A basic implementation example of OverlayCenter applying a watermark to a canvas with 70% opacity. ```go dst := imaging.OverlayCenter(canvas, watermark, 0.7) ``` -------------------------------- ### Histogram usage example Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/utils.md Example showing how to call Histogram and access the resulting luminance probabilities. ```go h := imaging.Histogram(src) bright := h[255] // probability of a pixel having luminance 255 // The histogram is normalized — it can be summed to check the total mass. var sum float64 for i := 0; i < 256; i++ { sum += h[i] } ``` -------------------------------- ### AdjustHue usage examples Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/adjust.md Examples showing how to shift the hue of an image by 90 degrees and -30 degrees. ```go // Shift hue by 90 degrees. dst := imaging.AdjustHue(src, 90) // Shift hue by -30 degrees. dst := imaging.AdjustHue(src, -30) ``` -------------------------------- ### Thumbnail function signature with example Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/resize.md The Thumbnail function signature and its documented example. It scales and crops the image to the specified width and height using the given filter. The example uses imaging.Lanczos. ```go // resize.go:344 // Thumbnail scales the image up or down using the specified resample filter, crops it // to the specified width and hight and returns the transformed image. // // Example: // // dstImage := imaging.Thumbnail(srcImage, 100, 100, imaging.Lanczos) // func Thumbnail(img image.Image, width, height int, filter ResampleFilter) *image.NRGBA ``` -------------------------------- ### Convolve5x5 averaging kernel example Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/convolution.md Example of applying a 5x5 averaging kernel with normalization enabled. ```go // A simple 5x5 averaging kernel. dst := imaging.Convolve5x5( src, [25]float64{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, &imaging.ConvolveOptions{Normalize: true}, ) ``` -------------------------------- ### Save usage and error handling Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/io.md Examples demonstrating basic usage of Save and handling unsupported file extensions. ```go // Basic use. err := imaging.Save(dst, "testdata/out_example.jpg") if err != nil { log.Fatalf("failed to save image: %v", err) } // Error handling — unsupported extension. err := imaging.Save(img, "out.unknown") if err != nil && err != imaging.ErrUnsupportedFormat { log.Fatalf("unexpected error: %v", err) } ``` -------------------------------- ### Complete imaging example: crop, resize, filter, and composite Source: https://github.com/disintegration/imaging/blob/master/README.md This example demonstrates a typical imaging workflow: open an image, crop to 300x300 using center anchor, resize to width 200, then create four variants (blur, grayscale with contrast and sharpen, invert, and convolve3x3). These are pasted into a 400x400 canvas and saved as JPEG. It shows the use of imaging.CropAnchor, Resize, Blur, Grayscale, AdjustContrast, Sharpen, Invert, Convolve3x3, New, Paste, and Save. ```go package main import ( "image" "image/color" "log" "github.com/disintegration/imaging" ) func main() { // Open a test image. src, err := imaging.Open("testdata/flowers.png") if err != nil { log.Fatalf("failed to open image: %v", err) } // Crop the original image to 300x300px size using the center anchor. src = imaging.CropAnchor(src, 300, 300, imaging.Center) // Resize the cropped image to width = 200px preserving the aspect ratio. src = imaging.Resize(src, 200, 0, imaging.Lanczos) // Create a blurred version of the image. img1 := imaging.Blur(src, 5) // Create a grayscale version of the image with higher contrast and sharpness. img2 := imaging.Grayscale(src) img2 = imaging.AdjustContrast(img2, 20) img2 = imaging.Sharpen(img2, 2) // Create an inverted version of the image. img3 := imaging.Invert(src) // Create an embossed version of the image using a convolution filter. img4 := imaging.Convolve3x3( src, [9]float64{ -1, -1, 0, -1, 1, 1, 0, 1, 1, }, nil, ) // Create a new image and paste the four produced images into it. dst := imaging.New(400, 400, color.NRGBA{0, 0, 0, 0}) dst = imaging.Paste(dst, img1, image.Pt(0, 0)) dst = imaging.Paste(dst, img2, image.Pt(0, 200)) dst = imaging.Paste(dst, img3, image.Pt(200, 0)) dst = imaging.Paste(dst, img4, image.Pt(200, 200)) // Save the resulting image as JPEG. err = imaging.Save(dst, "testdata/out_example.jpg") if err != nil { log.Fatalf("failed to save image: %v", err) } } ``` -------------------------------- ### AdjustSigmoid usage examples Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/adjust.md Examples demonstrating how to increase and decrease image contrast using the AdjustSigmoid function. ```go // Increase contrast around the 0.5 midpoint. dst := imaging.AdjustSigmoid(src, 0.5, 3.0) // Decrease contrast. dst := imaging.AdjustSigmoid(src, 0.5, -3.0) ``` -------------------------------- ### Thumbnail usage example Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/resize.md A concise usage example of Thumbnail, scaling and cropping the source image to 128x128 pixels using the CatmullRom filter. ```go dst := imaging.Thumbnail(src, 128, 128, imaging.CatmullRom) ``` -------------------------------- ### Convolve3x3 with custom options Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/convolution.md Example of applying a kernel with normalization, absolute values, and a bias offset. ```go // Normalize the kernel, take absolute values (e.g. for edge detection), add +128 bias. edge := imaging.Convolve3x3( src, [9]float64{ -1, -1, -1, -1, 8, -1, -1, -1, -1, }, &imaging.ConvolveOptions{ Normalize: true, Abs: true, Bias: 128, }, ) ``` -------------------------------- ### Paste usage example Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/compositing.md Example of creating a new background and pasting two images onto it at different positions. ```go dst := imaging.New(400, 400, color.NRGBA{0, 0, 0, 0}) dst = imaging.Paste(dst, thumb1, image.Pt(0, 0)) dst = imaging.Paste(dst, thumb2, image.Pt(0, 200)) ``` -------------------------------- ### AdjustSaturation usage examples Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/adjust.md Shows how to increase saturation by 25% and decrease by 10% using imaging.AdjustSaturation. ```go // Increase saturation by 25%. dst := imaging.AdjustSaturation(src, 25) // Decrease saturation by 10%. dst := imaging.AdjustSaturation(src, -10) ``` -------------------------------- ### SetMaxProcs usage example Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/utils.md Demonstrates how to set a concurrency limit before performing an image operation and how to clear it afterward. ```go // Allow at most 2 concurrent processing goroutines. imaging.SetMaxProcs(2) dst := imaging.Resize(src, 800, 600, imaging.Lanczos) // Clear the limit again (back to GOMAXPROCS-based count). imaging.SetMaxProcs(0) ``` -------------------------------- ### Grayscale usage example Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/adjust.md Shows how to call imaging.Grayscale on a source image to produce a grayscale version. ```go dst := imaging.Grayscale(src) ``` -------------------------------- ### FlipV usage example Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/transform.md Calls imaging.FlipV on a source image and assigns the result to dst. ```go dst := imaging.FlipV(src) ``` -------------------------------- ### PasteCenter usage example Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/compositing.md Basic usage of PasteCenter to combine two images. ```go dst := imaging.PasteCenter(canvas, logo) ``` -------------------------------- ### Save image with multiple EncodeOptions Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/io.md Example demonstrating how to pass multiple EncodeOptions to the imaging.Save function. ```go err := imaging.Save( img, "out.gif", imaging.GIFNumColors(128), imaging.GIFDrawer(draw.FloydSteinberg), ) if err != nil { log.Fatalf("failed to save image: %v", err) } ``` -------------------------------- ### Invert usage example Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/adjust.md Shows how to call imaging.Invert on a source image to produce an inverted version. ```go dst := imaging.Invert(src) ``` -------------------------------- ### Overlay usage examples Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/compositing.md Various ways to use the Overlay function, including blending images and handling opacity clamping. ```go // Blend two opaque images of equal size at 50% layer opacity. dst := imaging.Overlay(imageOne, imageTwo, image.Pt(0, 0), 0.5) // Draw a sprite at (50, 50) fully opaque. dst := imaging.Overlay(backgroundImage, spriteImage, image.Pt(50, 50), 1.0) // Opacity is clamped to [0, 1] — harmless to pass a value outside the range. dst := imaging.Overlay(bg, fg, image.Pt(0, 0), 1.5) // same as opacity = 1.0 ``` -------------------------------- ### FlipH usage example Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/transform.md Calls imaging.FlipH on a source image and assigns the result to dst. ```go dst := imaging.FlipH(src) ``` -------------------------------- ### Transpose usage example Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/transform.md Calls imaging.Transpose on a source image and assigns the result to dst. ```go dst := imaging.Transpose(src) ``` -------------------------------- ### AdjustFunc channel boosting Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/adjust.md Example of using AdjustFunc to boost every color channel by a fixed offset with clamping. ```go dst := imaging.AdjustFunc( src, func(c color.NRGBA) color.NRGBA { bump := func(v uint8) uint8 { r := int(v) + 32 if r > 255 { r = 255 } return uint8(r) } return color.NRGBA{bump(c.R), bump(c.G), bump(c.B), c.A} }, ) ``` -------------------------------- ### Convolve3x3 default usage Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/convolution.md Example of applying an emboss-style kernel using default convolution options. ```go // Emboss-style kernel from the README example (options = nil → defaults). dst := imaging.Convolve3x3( src, [9]float64{ -1, -1, 0, -1, 1, 1, 0, 1, 1, }, nil, ) ``` -------------------------------- ### Decode from memory buffer Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/io.md Example of decoding image data stored in a memory buffer. ```go buf := bytes.NewBuffer(imgData) img, err := imaging.Decode(buf) if err != nil { log.Fatalf("failed to decode: %v", err) } ``` -------------------------------- ### Resize to exact size and preserve aspect ratio Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/resize.md Two usage examples: one resizes to exact dimensions 128x128 with Lanczos, the other to width 800 while preserving aspect ratio with CatmullRom. Both assign the result to dst. ```go // Resize to exactly 128x128 with a high-quality filter. dst := imaging.Resize(src, 128, 128, imaging.Lanczos) // Resize to width 800, preserving the aspect ratio. dst := imaging.Resize(src, 800, 0, imaging.CatmullRom) ``` -------------------------------- ### Resize with NearestNeighbor filter Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/resize.md Example using NearestNeighbor filter, which has Support = 0 and disables filtering, using the nearest-neighbor path. Resizes to 320x240. ```go // Using NearestNeighbor disables filtering entirely (Support = 0). dst := imaging.Resize(src, 320, 240, imaging.NearestNeighbor) ``` -------------------------------- ### Rotate90, Rotate180, Rotate270 usage examples Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/transform.md Applies each fixed rotation to a source image. 90° and 270° swap width and height; 180° keeps dimensions. ```go dst90 := imaging.Rotate90(src) // counter-clockwise dst180 := imaging.Rotate180(src) dst270 := imaging.Rotate270(src) ``` -------------------------------- ### Save function signature and examples Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/io.md The Save function saves an image to a file, determining the format from the filename extension. ```go // io.go:268 // Save saves the image to file with the specified filename. // The format is determined from the filename extension: // "jpg" (or "jpeg"), "png", "gif", "tif" (or "tiff") and "bmp" are supported. // // Examples: // // // Save the image as PNG. // err := imaging.Save(img, "out.png") // // // Save the image as JPEG with optional quality parameter set to 80. // err := imaging.Save(img, "out.jpg", imaging.JPEGQuality(80)) // func Save(img image.Image, filename string, opts ...EncodeOption) (err error) ``` -------------------------------- ### Save image with JPEGQuality option Source: https://github.com/disintegration/imaging/blob/master/_autodocs/configuration.md Example of saving an image with a specific JPEG quality setting using the imaging.JPEGQuality option. ```go err := imaging.Save(img, "out.jpg", imaging.JPEGQuality(80)) ``` -------------------------------- ### Custom triangular filter example Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/resize.md Shows how to create a custom ResampleFilter with a triangular kernel and use it with imaging.Resize. The filter has a Support radius of 1.0 and returns 1-x for |x|<1, 0 otherwise. ```go // A custom triangular filter with a Support radius of 1.0. myFilter := imaging.ResampleFilter{ Support: 1.0, Kernel: func(x float64) float64 { x = math.Abs(x) if x < 1.0 { return 1.0 - x } return 0 }, } dst := imaging.Resize(src, 300, 300, myFilter) ``` -------------------------------- ### Replace file system backend for testing Source: https://github.com/disintegration/imaging/blob/master/_autodocs/configuration.md Demonstrates how to swap the global imaging.fs variable with a custom implementation, ensuring it is restored after the test completes. ```go prevFS := imaging.fs imaging.fs = myInMemoryFS{} defer func() { imaging.fs = prevFS }() ``` -------------------------------- ### AdjustFunc basic usage Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/adjust.md Example of using AdjustFunc to shift the red channel of an image by 16. ```go dstImage = imaging.AdjustFunc( srcImage, func(c color.NRGBA) color.NRGBA { // Shift the red channel by 16. r := int(c.R) + 16 if r > 255 { r = 255 } return color.NRGBA{uint8(r), c.G, c.B, c.A} } ) ``` -------------------------------- ### Define and initialize the fileSystem interface Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/io.md The fileSystem interface defines Create and Open operations. The localFS implementation is assigned to the global fs variable by default. ```go // io.go:21 type fileSystem interface { Create(string) (io.WriteCloser, error) Open(string) (io.ReadCloser, error) } // io.go:26 type localFS struct{} // io.go:31 var fs fileSystem = localFS{} ``` -------------------------------- ### Apply AutoOrientation in imaging.Open Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/io.md Demonstrates opening an image file with EXIF auto-orientation enabled. ```go img, err := imaging.Open("test.jpg", imaging.AutoOrientation(true)) if err != nil { log.Fatalf("failed to open image: %v", err) } ``` -------------------------------- ### Image resizing with imaging.Resize, Fit, and Fill Source: https://github.com/disintegration/imaging/blob/master/README.md Resize srcImage to 128x128px using Lanczos filter, resize to width 800px preserving aspect ratio, scale down to fit 800x600px bounding box, and resize and crop to fill 100x100px area. ```Go // Resize srcImage to size = 128x128px using the Lanczos filter. dstImage128 := imaging.Resize(srcImage, 128, 128, imaging.Lanczos) // Resize srcImage to width = 800px preserving the aspect ratio. dstImage800 := imaging.Resize(srcImage, 800, 0, imaging.Lanczos) // Scale down srcImage to fit the 800x600px bounding box. dstImageFit := imaging.Fit(srcImage, 800, 600, imaging.Lanczos) // Resize and crop the srcImage to fill the 100x100px area. dstImageFill := imaging.Fill(srcImage, 100, 100, imaging.Center, imaging.Lanczos) ``` -------------------------------- ### New Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/compositing.md Creates a new image with the specified width and height, filled with the specified color. Returns an empty image if dimensions are non-positive. ```APIDOC ## New ### Description Creates a new image with the specified width and height, and fills it with the specified color. ### Function Signature go func New(width, height int, fillColor color.Color) *image.NRGBA ### Parameters - **width** (int) - Required - Image width in pixels. - **height** (int) - Required - Image height in pixels. - **fillColor** (color.Color) - Required - Fill color; any type accepted by `color.NRGBAModel.Convert`. ### Returns - **\*image.NRGBA** - The new image of the given size filled with `fillColor` (converted to `color.NRGBA`). If `width <= 0 || height <= 0`, an empty image (`&image.NRGBA{}`) is returned. A fill color equal to `color.NRGBA{0, 0, 0, 0}` (transparent black) returns a newly allocated transparent image without explicit fill. ### Example go // A 400x400 transparent canvas. dst := imaging.New(400, 400, color.NRGBA{0, 0, 0, 0}) // An opaque white 100x100 canvas. dst := imaging.New(100, 100, color.White) ``` -------------------------------- ### Transverse usage example Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/transform.md Applies the Transverse transform to a source image, producing a new image with swapped dimensions. ```go dst := imaging.Transverse(src) ``` -------------------------------- ### Scale down to fit an 800x600 box with imaging.Fit Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/resize.md Shows how to call imaging.Fit to scale an image down to fit the 800x600 bounding box, preserving aspect ratio. ```go // Scale down to fit an 800x600 box (one dimension will equal the box limit). dst := imaging.Fit(src, 800, 600, imaging.Lanczos) ``` -------------------------------- ### Rotate usage examples Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/transform.md Rotates an image by 30 degrees counter-clockwise with black background, and by -45 degrees (clockwise) with transparent background. ```go // Rotate 30 degrees counter-clockwise; uncovered pixels are black. dst := imaging.Rotate(src, 30, color.NRGBA{0, 0, 0, 255}) // Rotate the other way; uncovered pixels are transparent. dst := imaging.Rotate(src, -45, color.NRGBA{0, 0, 0, 0}) ``` -------------------------------- ### imaging.Fit function signature and comment Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/resize.md Declares the Fit function, which scales down the source image to fit a maximum width and height. An example call is included in the doc comment. ```go // resize.go:224 // Fit scales down the image using the specified resample filter to fit the specified // maximum width and height and returns the transformed image. // // Example: // // dstImage := imaging.Fit(srcImage, 800, 600, imaging.Lanczos) // func Fit(img image.Image, width, height int, filter ResampleFilter) *image.NRGBA ``` -------------------------------- ### Fill a 640x480 area with top-left anchor Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/resize.md Demonstrates using imaging.Fill with a corner anchor to keep the top-left of the image. ```go // Use a corner anchor to keep the top-left of the image. dst := imaging.Fill(src, 640, 480, imaging.TopLeft, imaging.Linear) ``` -------------------------------- ### AdjustBrightness - Adjust image brightness Source: https://github.com/disintegration/imaging/blob/master/README.md Adjusts the brightness of the source image by the given percentage. Positive values brighten, negative values darken. The example uses a value of 20. ```Go dstImage := imaging.AdjustBrightness(srcImage, 20) ``` -------------------------------- ### imaging.Fill function signature and comment Source: https://github.com/disintegration/imaging/blob/master/_autodocs/api-reference/resize.md Declares the Fill function, which creates an image with exact dimensions by cropping the source to preserve aspect ratio. An example call is included in the doc comment. ```go // resize.go:265 // Fill creates an image with the specified dimensions and fills it with the scaled source image. // To achieve the correct aspect ratio without stretching, the source image will be cropped. // // Example: // // dstImage := imaging.Fill(srcImage, 800, 600, imaging.Center, imaging.Lanczos) // func Fill(img image.Image, width, height int, anchor Anchor, filter ResampleFilter) *image.NRGBA ``` -------------------------------- ### fileSystem interface and localFS struct Source: https://github.com/disintegration/imaging/blob/master/_autodocs/types.md Defines the fileSystem interface and the localFS struct. The interface requires Create and Open methods for file storage. localFS is the default zero-field struct that implements both methods by delegating to os.Create and os.Open. The global variable fs fileSystem = localFS{} is the single injection point for file storage. ```go // io.go:21 type fileSystem interface { Create(string) (io.WriteCloser, error) Open(string) (io.ReadCloser, error) } // io.go:26 type localFS struct{} ``` -------------------------------- ### AdjustSaturation - Adjust image saturation Source: https://github.com/disintegration/imaging/blob/master/README.md Adjusts the saturation of the source image by the given percentage. Positive values increase saturation, negative values decrease it. The example uses a value of 20. ```Go dstImage := imaging.AdjustSaturation(srcImage, 20) ``` -------------------------------- ### Compare ErrUnsupportedFormat Source: https://github.com/disintegration/imaging/blob/master/_autodocs/errors.md Compare the returned error against the package-defined ErrUnsupportedFormat value. ```go f, err := imaging.FormatFromExtension("webp") if err == imaging.ErrUnsupportedFormat { log.Fatalf("unsupported format") } ```