### Go Image Resizing Examples Source: https://github.com/disintegration/imaging/blob/master/README.md Demonstrates resizing images using different methods and filters like Lanczos. Includes resizing to a fixed size, preserving aspect ratio, fitting within bounds, and filling a specific area. ```Go dstImage128 := imaging.Resize(srcImage, 128, 128, imaging.Lanczos) dstImage800 := imaging.Resize(srcImage, 800, 0, imaging.Lanczos) dstImageFit := imaging.Fit(srcImage, 800, 600, imaging.Lanczos) dstImageFill := imaging.Fill(srcImage, 100, 100, imaging.Center, imaging.Lanczos) ``` -------------------------------- ### Full Image Manipulation Example Source: https://github.com/disintegration/imaging/blob/master/README.md Demonstrates a comprehensive image manipulation workflow including opening, cropping, resizing, applying filters (blur, grayscale, invert, convolve), and pasting images together. The final composite image is saved as a JPEG. ```Go package main import ( "image" "image/color" "log" "github.com/disintegration/imaging" ) func main() { // Open a test image. ssrc, 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) } } ``` -------------------------------- ### Create New Image Source: https://github.com/disintegration/imaging/blob/master/README.md Creates a new blank image with specified dimensions and background color. This serves as a canvas for pasting other images onto. ```Go dst := imaging.New(400, 400, color.NRGBA{0, 0, 0, 0}) ``` -------------------------------- ### Convert Image to Grayscale Source: https://github.com/disintegration/imaging/blob/master/README.md Converts a color image to grayscale. This function is often used as a precursor to other adjustments like contrast or sharpening. ```Go img2 := imaging.Grayscale(src) ``` -------------------------------- ### Paste Image onto Another Source: https://github.com/disintegration/imaging/blob/master/README.md Pastes one image onto another at a specified position. This is fundamental for compositing images or creating layouts. ```Go dst = imaging.Paste(dst, img1, image.Pt(0, 0)) ``` -------------------------------- ### Go Image Gaussian Blur Source: https://github.com/disintegration/imaging/blob/master/README.md Applies a Gaussian blur to an image. The sigma parameter controls the strength of the blur effect. ```Go dstImage := imaging.Blur(srcImage, 0.5) ``` -------------------------------- ### Resize Image Source: https://github.com/disintegration/imaging/blob/master/README.md Resizes an image to a specified width and height, optionally preserving the aspect ratio. The `Lanczos` filter is used for high-quality downsampling. ```Go src = imaging.Resize(src, 200, 0, imaging.Lanczos) ``` -------------------------------- ### Go Image Sharpening Source: https://github.com/disintegration/imaging/blob/master/README.md Sharpens an image using an internal Gaussian function. The sigma parameter adjusts the sharpening intensity. ```Go dstImage := imaging.Sharpen(srcImage, 0.5) ``` -------------------------------- ### Adjust Image Contrast Source: https://github.com/disintegration/imaging/blob/master/README.md Adjusts the contrast of a given image by a specified factor. This function is useful for enhancing or reducing the tonal differences in an image. ```Go dstImage := imaging.AdjustContrast(srcImage, 20) ``` -------------------------------- ### Save Image Source: https://github.com/disintegration/imaging/blob/master/README.md Saves an image to a file in a specified format (e.g., JPEG). Error handling is included for the save operation. ```Go err = imaging.Save(dst, "testdata/out_example.jpg") ``` -------------------------------- ### Open Image with Auto Orientation Source: https://github.com/disintegration/imaging/blob/master/README.md Opens an image file and automatically corrects its orientation based on EXIF data. This is crucial for handling images that might appear rotated due to camera settings. ```Go img, err := imaging.Open("test.jpg", imaging.AutoOrientation(true)) ``` -------------------------------- ### Crop Image with Anchor Source: https://github.com/disintegration/imaging/blob/master/README.md Crops an image to a specified width and height, using an anchor point to determine the region to keep. This is useful for precise image framing. ```Go src = imaging.CropAnchor(src, 300, 300, imaging.Center) ``` -------------------------------- ### Apply Convolution Filter Source: https://github.com/disintegration/imaging/blob/master/README.md Applies a custom 3x3 convolution kernel to an image. This allows for a wide range of effects, including edge detection, embossing, and custom blurs. ```Go img4 := imaging.Convolve3x3( src, [9]float64{ -1, -1, 0, -1, 1, 1, 0, 1, 1, }, nil, ) ``` -------------------------------- ### Adjust Image Saturation Source: https://github.com/disintegration/imaging/blob/master/README.md Alters the saturation of an image, affecting the intensity of colors. Positive values increase saturation, while negative values decrease it. ```Go dstImage := imaging.AdjustSaturation(srcImage, 20) ``` -------------------------------- ### Adjust Image Brightness Source: https://github.com/disintegration/imaging/blob/master/README.md Modifies the brightness of an image by a specified amount. This allows for lightening or darkening the overall image. ```Go dstImage := imaging.AdjustBrightness(srcImage, 20) ``` -------------------------------- ### Sharpen Image Source: https://github.com/disintegration/imaging/blob/master/README.md Applies a sharpening filter to an image, enhancing edge detail. This is often used after grayscale conversion or other softening effects. ```Go img2 = imaging.Sharpen(img2, 2) ``` -------------------------------- ### Adjust Image Hue Source: https://github.com/disintegration/imaging/blob/master/README.md Changes the hue of an image, which corresponds to the dominant color in the spectrum. This function allows for shifting colors. ```Go dstImage := imaging.AdjustHue(srcImage, 20) ``` -------------------------------- ### Apply Blur Filter Source: https://github.com/disintegration/imaging/blob/master/README.md Applies a Gaussian blur effect to an image with a specified radius. This can be used for softening images or creating artistic effects. ```Go img1 := imaging.Blur(src, 5) ``` -------------------------------- ### Invert Image Colors Source: https://github.com/disintegration/imaging/blob/master/README.md Inverts the colors of an image, creating a photographic negative effect. This is achieved by subtracting each color channel value from the maximum. ```Go img3 := imaging.Invert(src) ``` -------------------------------- ### Go Image Gamma Correction Source: https://github.com/disintegration/imaging/blob/master/README.md Adjusts the gamma correction of an image. The provided float value controls the gamma level. ```Go dstImage := imaging.AdjustGamma(srcImage, 0.75) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.