### Install imaging Package Source: https://pkg.go.dev/github.com/disintegration/imaging/index This command installs or updates the imaging package to the latest version. It is a prerequisite for using the package's functionalities in your Go project. ```go go get -u github.com/disintegration/imaging ``` -------------------------------- ### Go: Image Manipulation Example using imaging Source: https://pkg.go.dev/github.com/disintegration/imaging/index Demonstrates various image manipulation techniques including opening, cropping, resizing, blurring, grayscale conversion, inverting, and convolution using the 'imaging' package. It also shows how to composite multiple processed images into a new destination image and save the result. Requires the 'github.com/disintegration/imaging' package. ```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) } } ``` -------------------------------- ### Get Image Format from Extension with Go Source: https://pkg.go.dev/github.com/disintegration/imaging/index FormatFromExtension parses an image format from a given file extension string. It supports extensions like 'jpg'/'jpeg', 'png', 'gif', 'tif'/'tiff', and 'bmp', returning the corresponding Format and an error if unrecognized. ```go func FormatFromExtension(ext string) (Format, error) ``` -------------------------------- ### Get Image Format from Filename with Go Source: https://pkg.go.dev/github.com/disintegration/imaging/index FormatFromFilename determines the image format by parsing the provided filename. It recognizes common extensions such as 'jpg'/'jpeg', 'png', 'gif', 'tif'/'tiff', and 'bmp', returning the detected Format and an error if unsuccessful. ```go func FormatFromFilename(filename string) (Format, error) ``` -------------------------------- ### Get Image Histogram (Go) Source: https://pkg.go.dev/github.com/disintegration/imaging/index Returns a normalized histogram of an image as an array of 256 floats. Each element represents the probability of a pixel having a particular luminance value. ```Go func Histogram(img image.Image) [256]float64 ``` -------------------------------- ### Get String Representation of Image Format with Go Source: https://pkg.go.dev/github.com/disintegration/imaging/index The String method for the Format type returns a human-readable string representation of the image format (e.g., "JPEG", "PNG"). This is useful for logging or display purposes. ```go func (f Format) String() string ``` -------------------------------- ### Format and Options Source: https://pkg.go.dev/github.com/disintegration/imaging/index_tab=versions Details about image formats and encoding/decoding options. ```APIDOC ## Format and Options ### Format Represents the image format. - **Constants**: - `BMP` - `GIF` - `JPEG` - `PNG` - `TIFF` ### FormatFromExtension Determines the image format from a file extension. - **Method**: Not applicable (Function) - **Parameters**: - `ext` (string) - The file extension (e.g., ".jpg"). - **Returns**: `(Format, error)` - The detected format and an error if unrecognized. ### FormatFromFilename Determines the image format from a filename. - **Method**: Not applicable (Function) - **Parameters**: - `filename` (string) - The name of the file. - **Returns**: `(Format, error)` - The detected format and an error if unrecognized. ### PNGCompressionLevel Sets the PNG compression level for encoding. - **Method**: Not applicable (Function) - **Parameters**: - `level` (png.CompressionLevel) - The desired compression level. - **Returns**: `EncodeOption` - An encoding option. ### JPEGQuality Sets the JPEG quality for encoding. - **Method**: Not applicable (Function) - **Parameters**: - `quality` (int) - The desired quality level (0-100). - **Returns**: `EncodeOption` - An encoding option. ### GIFQuantizer Sets the GIF quantizer for encoding. - **Method**: Not applicable (Function) - **Parameters**: - `quantizer` (draw.Quantizer) - The quantizer to use. - **Returns**: `EncodeOption` - An encoding option. ### GIFDrawer Sets the GIF drawer for encoding. - **Method**: Not applicable (Function) - **Parameters**: - `drawer` (draw.Drawer) - The drawer to use. - **Returns**: `EncodeOption` - An encoding option. ### GIFNumColors Sets the number of colors for GIF encoding. - **Method**: Not applicable (Function) - **Parameters**: - `numColors` (int) - The desired number of colors. - **Returns**: `EncodeOption` - An encoding option. ### AutoOrientation Enables or disables automatic image orientation based on EXIF data during decoding. - **Method**: Not applicable (Function) - **Parameters**: - `enabled` (bool) - Whether to enable auto-orientation. - **Returns**: `DecodeOption` - A decoding option. ``` -------------------------------- ### Image Encoding Options in Go Source: https://pkg.go.dev/github.com/disintegration/imaging/index_tab=versions This Go code snippet shows how to apply specific encoding options when saving images using the imaging library. It demonstrates setting options for PNG compression levels and JPEG quality. These options allow fine-tuning the output file size and quality. ```Go package main import ( "image" "log" "github.com/disintegration/imaging" "image/png" ) func main() { // Example: Set PNG compression level pngOptions := []imaging.EncodeOption{ imaging.PNGCompressionLevel(png.BestCompression), } // Example: Set JPEG quality jpegOptions := []imaging.EncodeOption{ imaging.JPEGQuality(85), } // These options would be passed to the imaging.Encode function // For example: // err := imaging.Encode(w, img, imaging.PNG, pngOptions...) // err = imaging.Encode(w, img, imaging.JPEG, jpegOptions...) log.Println("Image encoding options examples prepared.") } ``` -------------------------------- ### Image Creation and Cloning Source: https://pkg.go.dev/github.com/disintegration/imaging/index_tab=versions Functions for creating new images and cloning existing ones. ```APIDOC ## Image Creation and Cloning ### New Creates a new blank image with the specified dimensions and fill color. - **Method**: Not applicable (Function) - **Parameters**: - `width` (int) - The width of the new image. - `height` (int) - The height of the new image. - `fillColor` (color.Color) - The color to fill the new image with. - **Returns**: `*image.NRGBA` - The newly created image. ### Clone Creates a copy of an existing image. - **Method**: Not applicable (Function) - **Parameters**: - `img` (image.Image) - The image to clone. - **Returns**: `*image.NRGBA` - A copy of the input image. ``` -------------------------------- ### Image Format Handling in Go Source: https://pkg.go.dev/github.com/disintegration/imaging/index_tab=versions This Go code snippet illustrates how to handle different image formats using the imaging library. It includes functions for determining a format from a file extension and for encoding images into specific formats. The library supports common formats like JPEG, PNG, GIF, BMP, and TIFF. ```Go package main import ( "fmt" "image" "io" "log" "os" "github.com/disintegration/imaging" ) func main() { // Example: Determine format from extension format, err := imaging.FormatFromExtension(".jpg") if err != nil { log.Fatalf("failed to get format from extension: %v", err) } fmt.Printf("Format from .jpg: %s\n", format.String()) format, err = imaging.FormatFromFilename("my_image.png") if err != nil { log.Fatalf("failed to get format from filename: %v", err) } fmt.Printf("Format from my_image.png: %s\n", format.String()) // Example: Encoding an image (replace with actual image loading and writer) var img image.Image // Placeholder for an actual image var w io.Writer = os.Stdout // Placeholder for an actual writer // err = imaging.Encode(w, img, imaging.PNG) // if err != nil { // log.Fatalf("failed to encode image: %v", err) // } log.Println("Image format handling examples executed.") } ``` -------------------------------- ### Linear ResampleFilter Initialization Source: https://pkg.go.dev/github.com/disintegration/imaging/index Initializes the Linear ResampleFilter, which implements bilinear resampling. It produces smooth output and is faster than cubic filters. ```go var Linear ResampleFilter ``` -------------------------------- ### Create a Copy of an Image Source: https://pkg.go.dev/github.com/disintegration/imaging/index Returns an exact copy of the provided image. This is useful when you need to perform modifications without altering the original image data. Dependencies: 'image' package. ```go func Clone(img image.Image) *image.NRGBA { // Implementation details would be here return nil } ``` -------------------------------- ### Fill Image with Scaled Source Source: https://pkg.go.dev/github.com/disintegration/imaging/index Creates a new image with specified dimensions and fills it by scaling the source image. The source image is cropped to maintain the correct aspect ratio without stretching. Uses a specified resampling filter. Dependencies: 'image' package. ```go func Fill(img image.Image, width, height int, anchor Anchor, filter ResampleFilter) *image.NRGBA { // Implementation details would be here return nil } // Example Usage: dstImage := imaging.Fill(srcImage, 800, 600, imaging.Center, imaging.Lanczos) ``` -------------------------------- ### Image Properties and Information Source: https://pkg.go.dev/github.com/disintegration/imaging/index_tab=versions Functions for retrieving information about an image. ```APIDOC ## Image Properties and Information ### Histogram Calculates the histogram of an image. - **Method**: Not applicable (Function) - **Parameters**: - `img` (image.Image) - The input image. - **Returns**: `[256]float64` - The histogram data. ``` -------------------------------- ### Create New Image with Fill Color (Go) Source: https://pkg.go.dev/github.com/disintegration/imaging/index Creates a new image with specified width and height, filled with a given color. ```Go func New(width, height int, fillColor color.Color) *image.NRGBA ``` -------------------------------- ### Image Transformations Source: https://pkg.go.dev/github.com/disintegration/imaging/index_tab=versions Functions for geometric transformations like cropping and fitting. ```APIDOC ## Image Transformations ### CropAnchor Crops an image to a specified size, anchored at a given position. - **Method**: Not applicable (Function) - **Parameters**: - `img` (image.Image) - The input image. - `width` (int) - The target width. - `height` (int) - The target height. - `anchor` (Anchor) - The anchor point for cropping. - **Returns**: `*image.NRGBA` - The cropped image. ### CropCenter Crops an image to a specified size, centered within the image. - **Method**: Not applicable (Function) - **Parameters**: - `img` (image.Image) - The input image. - `width` (int) - The target width. - `height` (int) - The target height. - **Returns**: `*image.NRGBA` - The cropped image. ### Fill Resizes an image to fit within specified dimensions while maintaining aspect ratio, cropping if necessary. - **Method**: Not applicable (Function) - **Parameters**: - `img` (image.Image) - The input image. - `width` (int) - The target width. - `height` (int) - The target height. - `anchor` (Anchor) - The anchor point for cropping. - `filter` (ResampleFilter) - The resampling filter to use. - **Returns**: `*image.NRGBA` - The filled image. ### Fit Resizes an image to fit within specified dimensions while maintaining aspect ratio, without cropping. - **Method**: Not applicable (Function) - **Parameters**: - `img` (image.Image) - The input image. - `width` (int) - The target width. - `height` (int) - The target height. - `filter` (ResampleFilter) - The resampling filter to use. - **Returns**: `*image.NRGBA` - The fitted image. ### Thumbnail Creates a thumbnail of an image, resizing it to fit within specified dimensions while maintaining aspect ratio. - **Method**: Not applicable (Function) - **Parameters**: - `img` (image.Image) - The input image. - `width` (int) - The maximum width of the thumbnail. - `height` (int) - The maximum height of the thumbnail. - `filter` (ResampleFilter) - The resampling filter to use. - **Returns**: `*image.NRGBA` - The thumbnail image. ``` -------------------------------- ### Image Manipulation Functions in Go Source: https://pkg.go.dev/github.com/disintegration/imaging/index_tab=versions This Go code snippet demonstrates various image manipulation functions provided by the imaging library. These functions allow for operations like resizing, cropping, rotating, flipping, color adjustments, and applying filters. They typically take an image.Image as input and return a modified image.Image or an NRGBA pointer. ```Go package main import ( "image" "image/color" "log" "github.com/disintegration/imaging" ) func main() { // Load an image (example: assume 'img' is an image.Image) // img, err := imaging.Open("path/to/your/image.jpg") // if err != nil { // log.Fatalf("failed to open image: %v", err) // } // Example usage of some functions (replace with actual image loading) var img image.Image // Placeholder for an actual image // Resize image resizedImg := imaging.Resize(img, 200, 150, imaging.Lanczos) // Crop image croppedImg := imaging.Crop(img, image.Rect(10, 10, 100, 100)) // Rotate image rotatedImg := imaging.Rotate(img, 90, color.Black) // Adjust brightness brightenedImg := imaging.AdjustBrightness(img, 20) // Convert to grayscale grayImg := imaging.Grayscale(img) // Save the modified image (example) // err = imaging.Save(resizedImg, "path/to/save/resized.jpg") // if err != nil { // log.Fatalf("failed to save image: %v", err) // } log.Println("Image manipulation examples executed.") } ``` -------------------------------- ### NearestNeighbor ResampleFilter Initialization Source: https://pkg.go.dev/github.com/disintegration/imaging/index Initializes the NearestNeighbor ResampleFilter, the fastest resampling filter available. It does not perform anti-aliasing. ```go var NearestNeighbor ResampleFilter ``` -------------------------------- ### Image Composition Source: https://pkg.go.dev/github.com/disintegration/imaging/index_tab=versions Functions for combining multiple images. ```APIDOC ## Image Composition ### Overlay Overlays an image onto a background image at a specified position with opacity. - **Method**: Not applicable (Function) - **Parameters**: - `background` (image.Image) - The background image. - `img` (image.Image) - The image to overlay. - `pos` (image.Point) - The position to overlay the image. - `opacity` (float64) - The opacity of the overlay. - **Returns**: `*image.NRGBA` - The resulting composed image. ### OverlayCenter Overlays an image onto the center of a background image with opacity. - **Method**: Not applicable (Function) - **Parameters**: - `background` (image.Image) - The background image. - `img` (image.Image) - The image to overlay. - `opacity` (float64) - The opacity of the overlay. - **Returns**: `*image.NRGBA` - The resulting composed image. ### Paste Pastes an image onto a background image at a specified position. - **Method**: Not applicable (Function) - **Parameters**: - `background` (image.Image) - The background image. - `img` (image.Image) - The image to paste. - `pos` (image.Point) - The position to paste the image. - **Returns**: `*image.NRGBA` - The resulting composed image. ### PasteCenter Pastes an image onto the center of a background image. - **Method**: Not applicable (Function) - **Parameters**: - `background` (image.Image) - The background image. - `img` (image.Image) - The image to paste. - **Returns**: `*image.NRGBA` - The resulting composed image. ``` -------------------------------- ### Create Thumbnail Image with Go Source: https://pkg.go.dev/github.com/disintegration/imaging/index The Thumbnail function resizes an image to fit within specified dimensions using a given resampling filter, then crops it to the exact width and height. It accepts an image.Image, target width and height (int), and a ResampleFilter, returning a *image.NRGBA. ```go func Thumbnail(img image.Image, width, height int, filter ResampleFilter) *image.NRGBA ``` ```go dstImage := imaging.Thumbnail(srcImage, 100, 100, imaging.Lanczos) ``` -------------------------------- ### Resampling Filters Source: https://pkg.go.dev/github.com/disintegration/imaging/index_tab=versions Available resampling filters for resizing operations. ```APIDOC ## Resampling Filters ### ResampleFilter Defines a resampling filter. - **Fields**: - `Kernel` (func(float64) float64) - The kernel function. - `Support` (float64) - The support of the kernel. - **Available Filters**: - `BSpline` - `Bartlett` - `Blackman` - `Box` - `CatmullRom` - `Cosine` - `Gaussian` - `Hamming` - `Hann` - `Hermite` - `Lanczos` - `Linear` - `MitchellNetravali` - `NearestNeighbor` - `Welch` ``` -------------------------------- ### Clone API Source: https://pkg.go.dev/github.com/disintegration/imaging/index Creates a copy of an image. ```APIDOC ## Clone API ### Description Returns a copy of the given image. ### Method N/A (Go function) ### Endpoint N/A (Go function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **img** (image.Image) - The source image to copy. ### Request Example ```go clonedImage := imaging.Clone(srcImage) ``` ### Response #### Success Response (200) - ***image.NRGBA** - A copy of the input image. #### Response Example ```go // clonedImage will hold the copied image ``` ``` -------------------------------- ### Image Resizing with Various Filters Source: https://pkg.go.dev/github.com/disintegration/imaging/index Demonstrates different methods for resizing images using the imaging package. It shows how to resize to fixed dimensions, preserve aspect ratio, fit within bounds, and fill a specific area. The Lanczos filter is commonly used for high-quality resizing. ```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) ``` -------------------------------- ### Overlay Image onto Background with Opacity (Go) Source: https://pkg.go.dev/github.com/disintegration/imaging/index Draws one image over another at a specified position with a given opacity for the overlaid image. The opacity must be between 0.0 and 1.0. ```Go func Overlay(background, img image.Image, pos image.Point, opacity float64) *image.NRGBA ``` -------------------------------- ### Box ResampleFilter Initialization Source: https://pkg.go.dev/github.com/disintegration/imaging/index Initializes the Box ResampleFilter, a simple and fast averaging filter. It is generally recommended for downscaling and behaves like NearestNeighbor when upscaling. ```go var Box ResampleFilter ``` -------------------------------- ### Adjust Image Contrast - Go Source: https://pkg.go.dev/github.com/disintegration/imaging/index Adjusts the contrast of an image by a given percentage. The percentage should be between -100 and 100. A value of 0 returns the original image, and -100 results in a solid gray image. ```go func AdjustContrast(img image.Image, percentage float64) *image.NRGBA ``` ```go dstImage = imaging.AdjustContrast(srcImage, -10) // Decrease image contrast by 10%. dstImage = imaging.AdjustContrast(srcImage, 20) // Increase image contrast by 20%. ``` -------------------------------- ### Image Manipulation Functions Source: https://pkg.go.dev/github.com/disintegration/imaging/index_tab=versions This section details the core image manipulation functions provided by the imaging library. ```APIDOC ## Image Manipulation Functions ### AdjustBrightness Adjusts the brightness of an image. - **Method**: Not applicable (Function) - **Parameters**: - `img` (image.Image) - The input image. - `percentage` (float64) - The percentage to adjust brightness by. - **Returns**: `*image.NRGBA` - The adjusted image. ### AdjustContrast Adjusts the contrast of an image. - **Method**: Not applicable (Function) - **Parameters**: - `img` (image.Image) - The input image. - `percentage` (float64) - The percentage to adjust contrast by. - **Returns**: `*image.NRGBA` - The adjusted image. ### AdjustSaturation Adjusts the saturation of an image. - **Method**: Not applicable (Function) - **Parameters**: - `img` (image.Image) - The input image. - `percentage` (float64) - The percentage to adjust saturation by. - **Returns**: `*image.NRGBA` - The adjusted image. ### Blur Applies a blur filter to an image. - **Method**: Not applicable (Function) - **Parameters**: - `img` (image.Image) - The input image. - `sigma` (float64) - The sigma value for the blur. - **Returns**: `*image.NRGBA` - The blurred image. ### Crop Crops an image to a specified rectangle. - **Method**: Not applicable (Function) - **Parameters**: - `img` (image.Image) - The input image. - `rect` (image.Rectangle) - The cropping rectangle. - **Returns**: `*image.NRGBA` - The cropped image. ### FlipH Flips an image horizontally. - **Method**: Not applicable (Function) - **Parameters**: - `img` (image.Image) - The input image. - **Returns**: `*image.NRGBA` - The horizontally flipped image. ### FlipV Flips an image vertically. - **Method**: Not applicable (Function) - **Parameters**: - `img` (image.Image) - The input image. - **Returns**: `*image.NRGBA` - The vertically flipped image. ### Grayscale Converts an image to grayscale. - **Method**: Not applicable (Function) - **Parameters**: - `img` (image.Image) - The input image. - **Returns**: `*image.NRGBA` - The grayscale image. ### Invert Inverts the colors of an image. - **Method**: Not applicable (Function) - **Parameters**: - `img` (image.Image) - The input image. - **Returns**: `*image.NRGBA` - The inverted image. ### Resize Resizes an image to the specified width and height using a given filter. - **Method**: Not applicable (Function) - **Parameters**: - `img` (image.Image) - The input image. - `width` (int) - The target width. - `height` (int) - The target height. - `filter` (ResampleFilter) - The resampling filter to use. - **Returns**: `*image.NRGBA` - The resized image. ### Rotate90 Rotates an image by 90 degrees clockwise. - **Method**: Not applicable (Function) - **Parameters**: - `img` (image.Image) - The input image. - **Returns**: `*image.NRGBA` - The rotated image. ### Rotate180 Rotates an image by 180 degrees. - **Method**: Not applicable (Function) - **Parameters**: - `img` (image.Image) - The input image. - **Returns**: `*image.NRGBA` - The rotated image. ### Rotate270 Rotates an image by 270 degrees clockwise. - **Method**: Not applicable (Function) - **Parameters**: - `img` (image.Image) - The input image. - **Returns**: `*image.NRGBA` - The rotated image. ### Sharpen Applies a sharpen filter to an image. - **Method**: Not applicable (Function) - **Parameters**: - `img` (image.Image) - The input image. - `sigma` (float64) - The sigma value for the sharpen. - **Returns**: `*image.NRGBA` - The sharpened image. ### Transpose Transposes an image (swaps rows and columns). - **Method**: Not applicable (Function) - **Parameters**: - `img` (image.Image) - The input image. - **Returns**: `*image.NRGBA` - The transposed image. ### Transverse Transverses an image (swaps rows and columns, then flips horizontally). - **Method**: Not applicable (Function) - **Parameters**: - `img` (image.Image) - The input image. - **Returns**: `*image.NRGBA` - The transversed image. ``` -------------------------------- ### Convert Image to Grayscale (Go) Source: https://pkg.go.dev/github.com/disintegration/imaging/index Produces a grayscale version of the input image. Returns the transformed image. ```Go func Grayscale(img image.Image) *image.NRGBA ``` -------------------------------- ### Overlay Image Centered with Opacity (Go) Source: https://pkg.go.dev/github.com/disintegration/imaging/index Overlays an image onto the center of a background image with specified opacity. The opacity must be between 0.0 and 1.0. ```Go func OverlayCenter(background, img image.Image, opacity float64) *image.NRGBA ``` -------------------------------- ### Image Decoding and Encoding Source: https://pkg.go.dev/github.com/disintegration/imaging/index_tab=versions Functions for decoding images from various sources and encoding them into different formats. ```APIDOC ## Image Decoding and Encoding ### Decode Decodes an image from a reader. - **Method**: Not applicable (Function) - **Parameters**: - `r` (io.Reader) - The reader to decode from. - **Returns**: `(image.Image, error)` - The decoded image and an error if any. ### Encode Encodes an image to a writer in a specified format. - **Method**: Not applicable (Function) - **Parameters**: - `w` (io.Writer) - The writer to encode to. - `img` (image.Image) - The image to encode. - `format` (Format) - The desired image format. - **Returns**: `error` - An error if encoding fails. ### Open Opens an image from a file. - **Method**: Not applicable (Function) - **Parameters**: - `filename` (string) - The path to the image file. - **Returns**: `(image.Image, error)` - The opened image and an error if any. ### Save Saves an image to a file. - **Method**: Not applicable (Function) - **Parameters**: - `img` (image.Image) - The image to save. - `filename` (string) - The path to save the file to. - **Returns**: `error` - An error if saving fails. ``` -------------------------------- ### Anchor Points Source: https://pkg.go.dev/github.com/disintegration/imaging/index_tab=versions Enumeration of anchor points for cropping and positioning. ```APIDOC ## Anchor Points ### Anchor Represents an anchor point within an image. - **Constants**: - `TopLeft` - `Top` - `TopRight` - `Left` - `Center` - `Right` - `BottomLeft` - `Bottom` - `BottomRight` ``` -------------------------------- ### CatmullRom ResampleFilter Initialization Source: https://pkg.go.dev/github.com/disintegration/imaging/index Initializes the CatmullRom ResampleFilter, a sharp cubic filter known for its speed and quality, comparable to Lanczos. It's defined as a BC-spline with B=0 and C=0.5. ```go var CatmullRom ResampleFilter ``` -------------------------------- ### Paste Image onto Background at Position (Go) Source: https://pkg.go.dev/github.com/disintegration/imaging/index Pastes one image onto another at a specified position. Returns the combined image. ```Go func Paste(background, img image.Image, pos image.Point) *image.NRGBA ``` -------------------------------- ### BSpline ResampleFilter Initialization Source: https://pkg.go.dev/github.com/disintegration/imaging/index Initializes the BSpline ResampleFilter, a smooth cubic filter. This filter is an implementation of the BC-spline with specific B and C parameters. ```go var BSpline ResampleFilter ``` -------------------------------- ### Convolve5x5 API Source: https://pkg.go.dev/github.com/disintegration/imaging/index Applies a 5x5 convolution kernel to an image. ```APIDOC ## Convolve5x5 API ### Description Convolves the image with the specified 5x5 convolution kernel. Default parameters are used if a nil *ConvolveOptions is passed. ### Method N/A (Go function) ### Endpoint N/A (Go function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **img** (image.Image) - The source image. - **kernel** ([25]float64) - The 5x5 convolution kernel. - **options** (*ConvolveOptions) - Optional parameters for convolution. If nil, defaults are used. ### Request Example ```go // Example kernel for edge detection kernel := [25]float64{ /* ... 25 float64 values ... */ } options := &imaging.ConvolveOptions{ // Example options // Set options if needed } dstImage := imaging.Convolve5x5(srcImage, kernel, options) ``` ### Response #### Success Response (200) - ***image.NRGBA** - The convolved image. #### Response Example ```go // dstImage will hold the result ``` ``` -------------------------------- ### Blackman ResampleFilter Initialization Source: https://pkg.go.dev/github.com/disintegration/imaging/index Initializes the Blackman ResampleFilter, employing a Blackman-windowed sinc function. Similar to Bartlett, it features 3 lobes. ```go var Blackman ResampleFilter ``` -------------------------------- ### Gaussian ResampleFilter Initialization Source: https://pkg.go.dev/github.com/disintegration/imaging/index Initializes the Gaussian ResampleFilter, a filter designed for Gaussian blurring effects in image processing. It's a standard filter for smoothing images. ```go var Gaussian ResampleFilter ``` -------------------------------- ### Open Image from File (Go) Source: https://pkg.go.dev/github.com/disintegration/imaging/index Loads an image from a specified file path. Supports decoding options like automatic orientation correction. ```Go func Open(filename string, opts ...DecodeOption) (image.Image, error) ``` -------------------------------- ### Convolution Operations in Go Source: https://pkg.go.dev/github.com/disintegration/imaging/index_tab=versions This Go code snippet demonstrates the use of convolution filters (3x3 and 5x5 kernels) for image processing with the imaging library. It allows for advanced image effects like blurring or sharpening by applying custom kernels. The `ConvolveOptions` struct enables controlling normalization and absolute value application. ```Go package main import ( "image" "log" "github.com/disintegration/imaging" ) func main() { // Example: Apply a 3x3 convolution kernel var img image.Image // Placeholder for an actual image kernel3x3 := [9]float64{ -1, -1, -1, -1, 8, -1, -1, -1, -1, } // Example: Edge detection kernel options := &imaging.ConvolveOptions{ Normalize: true, Abs: true, } convolvedImg3x3 := imaging.Convolve3x3(img, kernel3x3, options) // Example: Apply a 5x5 convolution kernel kernel5x5 := [25]float64{ // Define a 5x5 kernel here } convolvedImg5x5 := imaging.Convolve5x5(img, kernel5x5, options) log.Println("Convolution operations examples prepared.") } ``` -------------------------------- ### Welch ResampleFilter Initialization Source: https://pkg.go.dev/github.com/disintegration/imaging/index Initializes the Welch ResampleFilter, which uses a Welch-windowed sinc function. This filter is characterized by a parabolic window and 3 lobes. ```go var Welch ResampleFilter ``` -------------------------------- ### Convolve Image with 5x5 Kernel Source: https://pkg.go.dev/github.com/disintegration/imaging/index Applies a 5x5 convolution kernel to an image for more complex filtering operations. Default parameters are used if ConvolveOptions is nil. Dependencies: 'image' package. ```go func Convolve5x5(img image.Image, kernel [25]float64, options *ConvolveOptions) *image.NRGBA { // Implementation details would be here return nil } ``` -------------------------------- ### Convolution Filters Source: https://pkg.go.dev/github.com/disintegration/imaging/index_tab=versions Functions for applying 3x3 and 5x5 convolution kernels. ```APIDOC ## Convolution Filters ### Convolve3x3 Applies a 3x3 convolution kernel to an image. - **Method**: Not applicable (Function) - **Parameters**: - `img` (image.Image) - The input image. - `kernel` ([9]float64) - The 3x3 convolution kernel. - `options` (*ConvolveOptions) - Options for the convolution. - **Returns**: `*image.NRGBA` - The convolved image. ### Convolve5x5 Applies a 5x5 convolution kernel to an image. - **Method**: Not applicable (Function) - **Parameters**: - `img` (image.Image) - The input image. - `kernel` ([25]float64) - The 5x5 convolution kernel. - `options` (*ConvolveOptions) - Options for the convolution. - **Returns**: `*image.NRGBA` - The convolved image. ### ConvolveOptions Options for convolution operations. - **Fields**: - `Abs` (bool) - Whether to take the absolute value of the result. - `Bias` (int) - Bias to add to the result. - `Normalize` (bool) - Whether to normalize the result. ``` -------------------------------- ### Lanczos ResampleFilter Initialization Source: https://pkg.go.dev/github.com/disintegration/imaging/index Initializes the Lanczos ResampleFilter, a high-quality resampling filter known for sharp results, particularly suitable for photographic images. It uses a 3-lobe sinc function. ```go var Lanczos ResampleFilter ``` -------------------------------- ### MitchellNetravali ResampleFilter Initialization Source: https://pkg.go.dev/github.com/disintegration/imaging/index Initializes the MitchellNetravali ResampleFilter, a cubic filter that balances smoothness and ringing artifacts. It's a BC-spline with B=1/3 and C=1/3. ```go var MitchellNetravali ResampleFilter ``` -------------------------------- ### Sharpen Image with Go Source: https://pkg.go.dev/github.com/disintegration/imaging/index The Sharpen function creates a sharpened version of an image. The sigma parameter controls the degree of sharpening and must be a positive value. It takes an image.Image and a float64 sigma as input and returns a *image.NRGBA. ```go func Sharpen(img image.Image, sigma float64) *image.NRGBA ``` ```go dstImage := imaging.Sharpen(srcImage, 3.5) ``` -------------------------------- ### Bartlett ResampleFilter Initialization Source: https://pkg.go.dev/github.com/disintegration/imaging/index Initializes the Bartlett ResampleFilter, which uses a Bartlett-windowed sinc function. It is characterized by 3 lobes and is suitable for certain image processing tasks. ```go var Bartlett ResampleFilter ``` -------------------------------- ### Adjust Image Contrast using Sigmoid Function Source: https://pkg.go.dev/github.com/disintegration/imaging/index Applies a non-linear contrast adjustment using a sigmoidal function, which helps preserve highlight and shadow details. The midpoint (0-1) defines the contrast midpoint, and the factor (-10 to 10) controls the intensity of the contrast change. Dependencies: 'image' package. ```go func AdjustSigmoid(img image.Image, midpoint, factor float64) *image.NRGBA { // Implementation details would be here return nil } // Example Usage: dstImage = imaging.AdjustSigmoid(srcImage, 0.5, 3.0) // Increase the contrast. dstImage = imaging.AdjustSigmoid(srcImage, 0.5, -3.0) // Decrease the contrast. ``` -------------------------------- ### AdjustContrast Source: https://pkg.go.dev/github.com/disintegration/imaging/index AdjustContrast changes the contrast of the image using the percentage parameter and returns the adjusted image. The percentage must be in range (-100, 100). ```APIDOC ## AdjustContrast ### Description AdjustContrast changes the contrast of the image using the percentage parameter and returns the adjusted image. The percentage must be in range (-100, 100). The percentage = 0 gives the original image. The percentage = -100 gives solid gray image. ### Function Signature ```go func AdjustContrast(img image.Image, percentage float64) *image.NRGBA ``` ### Parameters * **img** (image.Image) - The input image. * **percentage** (float64) - The percentage to adjust contrast by. Range: (-100, 100). ### Returns * (*image.NRGBA) - The adjusted image. ### Examples ```go dstImage = imaging.AdjustContrast(srcImage, -10) // Decrease image contrast by 10%. dstImage = imaging.AdjustContrast(srcImage, 20) // Increase image contrast by 20%. ``` ``` -------------------------------- ### Convolve3x3 API Source: https://pkg.go.dev/github.com/disintegration/imaging/index Applies a 3x3 convolution kernel to an image. ```APIDOC ## Convolve3x3 API ### Description Convolves the image with the specified 3x3 convolution kernel. Default parameters are used if a nil *ConvolveOptions is passed. ### Method N/A (Go function) ### Endpoint N/A (Go function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **img** (image.Image) - The source image. - **kernel** ([9]float64) - The 3x3 convolution kernel. - **options** (*ConvolveOptions) - Optional parameters for convolution. If nil, defaults are used. ### Request Example ```go // Example kernel for sharpening kernel := [9]float64{-1, -1, -1, -1, 8, -1, -1, -1, -1} options := &imaging.ConvolveOptions{ // Example options // Set options if needed } dstImage := imaging.Convolve3x3(srcImage, kernel, options) ``` ### Response #### Success Response (200) - ***image.NRGBA** - The convolved image. #### Response Example ```go // dstImage will hold the result ``` ``` -------------------------------- ### Adjust Image Brightness - Go Source: https://pkg.go.dev/github.com/disintegration/imaging/index Adjusts the brightness of an image by a given percentage. The percentage should be between -100 and 100. A value of 0 returns the original image, -100 results in a black image, and 100 results in a white image. ```go func AdjustBrightness(img image.Image, percentage float64) *image.NRGBA ``` ```go dstImage = imaging.AdjustBrightness(srcImage, -15) // Decrease image brightness by 15%. dstImage = imaging.AdjustBrightness(srcImage, 10) // Increase image brightness by 10%. ``` -------------------------------- ### Paste Image Centered onto Background (Go) Source: https://pkg.go.dev/github.com/disintegration/imaging/index Pastes an image onto the center of a background image. Returns the combined image. ```Go func PasteCenter(background, img image.Image) *image.NRGBA ``` -------------------------------- ### Fill API Source: https://pkg.go.dev/github.com/disintegration/imaging/index Resizes an image to specified dimensions, maintaining aspect ratio by cropping. ```APIDOC ## Fill API ### Description 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. ### Method N/A (Go function) ### Endpoint N/A (Go function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **img** (image.Image) - The source image. - **width** (int) - The desired width of the output image. - **height** (int) - The desired height of the output image. - **anchor** (Anchor) - The anchor point used for cropping to maintain aspect ratio (e.g., `imaging.Center`). - **filter** (ResampleFilter) - The resampling filter to use (e.g., `imaging.Lanczos`). ### Request Example ```go dstImage := imaging.Fill(srcImage, 800, 600, imaging.Center, imaging.Lanczos) ``` ### Response #### Success Response (200) - ***image.NRGBA** - The resized and cropped image. #### Response Example ```go // dstImage will hold the result ``` ``` -------------------------------- ### AdjustBrightness Source: https://pkg.go.dev/github.com/disintegration/imaging/index AdjustBrightness changes the brightness of the image using the percentage parameter and returns the adjusted image. The percentage must be in range (-100, 100). ```APIDOC ## AdjustBrightness ### Description AdjustBrightness changes the brightness of the image using the percentage parameter and returns the adjusted image. The percentage must be in range (-100, 100). The percentage = 0 gives the original image. The percentage = -100 gives solid black image. The percentage = 100 gives solid white image. ### Function Signature ```go func AdjustBrightness(img image.Image, percentage float64) *image.NRGBA ``` ### Parameters * **img** (image.Image) - The input image. * **percentage** (float64) - The percentage to adjust brightness by. Range: (-100, 100). ### Returns * (*image.NRGBA) - The adjusted image. ### Examples ```go dstImage = imaging.AdjustBrightness(srcImage, -15) // Decrease image brightness by 15%. dstImage = imaging.AdjustBrightness(srcImage, 10) // Increase image brightness by 10%. ``` ``` -------------------------------- ### Adjust Image Saturation Source: https://pkg.go.dev/github.com/disintegration/imaging/index Changes the color saturation of an image by a given percentage. The percentage must be between -100 and 100. A percentage of 0 leaves the saturation unchanged, 100 doubles it, and -100 results in a grayscale image. Dependencies: 'image' package. ```go func AdjustSaturation(img image.Image, percentage float64) *image.NRGBA { // Implementation details would be here return nil } // Example Usage: dstImage = imaging.AdjustSaturation(srcImage, 25) // Increase image saturation by 25%. dstImage = imaging.AdjustSaturation(srcImage, -10) // Decrease image saturation by 10%. ``` -------------------------------- ### Set GIF Quantizer with Go Source: https://pkg.go.dev/github.com/disintegration/imaging/index The GIFQuantizer function returns an EncodeOption that specifies a draw.Quantizer for generating the palette of a GIF image. This provides control over how colors are selected for the GIF. ```go func GIFQuantizer(quantizer draw.Quantizer) EncodeOption ``` -------------------------------- ### Cosine ResampleFilter Initialization Source: https://pkg.go.dev/github.com/disintegration/imaging/index Initializes the Cosine ResampleFilter, utilizing a Cosine-windowed sinc function with 3 lobes. This filter is part of the sinc-based filter family. ```go var Cosine ResampleFilter ```