Documentation ¶
Overview ¶
manipulating images pixel by pixel
Index ¶
- func AdjustBrightness(img image.Image, adjustment float64) image.Image
- func AdjustContrast(img image.Image, factor float64) image.Image
- func Blur(img image.Image) image.Image
- func EachPixel(file *os.File, f func(uint8, uint8, uint8, uint8) (uint8, uint8, uint8, uint8)) (image.Image, error)
- func EachPixelOfImage(src image.Image, ...) (image.Image, error)
- func EdgeDetect(img image.Image) image.Image
- func Edgedetect(img image.Image) image.Image
- func FlipHorizontal(img image.Image) image.Image
- func GaussianBlur(img image.Image) image.Image
- func GrayAt(img image.Image, x, y int) uint8
- func Grayscale(img image.Image) image.Image
- func Invert(img image.Image) (image.Image, error)
- func LoadImage(filename string) (image.Image, error)
- func NearestNeighbor(img image.Image, newWidth, newHeight int) (*image.NRGBA, error)
- func ResizeNearestNeighbor(file *os.File, newWidth, newHeight int) (*image.NRGBA, error)
- func Rotate90(img image.Image) image.Image
- func SaveImage(img image.Image, filename string) error
- func Sepia(img image.Image) image.Image
- func Sharpen(img image.Image) image.Image
- func Threshold(img image.Image, threshold uint8) image.Image
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AdjustBrightness ¶ added in v0.18.0
AdjustBrightness adjusts the brightness of an image
Example ¶
package main import ( "fmt" "image" "image/png" "os" "simonwaldherr.de/go/golibs/graphics" ) func main() { img := createTestImage() brightImg := graphics.AdjustBrightness(img, 30) saveImage("brightness_example.png", brightImg) fmt.Println("Brightness adjusted image saved to brightness_example.png") } // createTestImage creates a simple test image func createTestImage() image.Image { img, _ := graphics.LoadImage("img.jpg") return img } // saveImage saves an image to a file func saveImage(filename string, img image.Image) { f, err := os.Create(filename) if err != nil { fmt.Println("Failed to create file:", err) return } defer f.Close() err = png.Encode(f, img) if err != nil { fmt.Println("Failed to encode image:", err) } }
Output: Brightness adjusted image saved to brightness_example.png
func AdjustContrast ¶ added in v0.18.0
AdjustContrast adjusts the contrast of an image
Example ¶
package main import ( "fmt" "image" "image/png" "os" "simonwaldherr.de/go/golibs/graphics" ) func main() { img := createTestImage() contrastImg := graphics.AdjustContrast(img, 1.5) saveImage("contrast_example.png", contrastImg) fmt.Println("Contrast adjusted image saved to contrast_example.png") } // createTestImage creates a simple test image func createTestImage() image.Image { img, _ := graphics.LoadImage("img.jpg") return img } // saveImage saves an image to a file func saveImage(filename string, img image.Image) { f, err := os.Create(filename) if err != nil { fmt.Println("Failed to create file:", err) return } defer f.Close() err = png.Encode(f, img) if err != nil { fmt.Println("Failed to encode image:", err) } }
Output: Contrast adjusted image saved to contrast_example.png
func EachPixel ¶
func EachPixel(file *os.File, f func(uint8, uint8, uint8, uint8) (uint8, uint8, uint8, uint8)) (image.Image, error)
EachPixel applies a function to each pixel of an image
func EachPixelOfImage ¶ added in v0.15.0
func EachPixelOfImage(src image.Image, f func(uint8, uint8, uint8, uint8) (uint8, uint8, uint8, uint8)) (image.Image, error)
EachPixelOfImage applies a function to each pixel of an image
func EdgeDetect ¶ added in v0.18.0
EdgeDetect detects edges in a grayscale image.
Example ¶
package main import ( "fmt" "image" "image/png" "os" "simonwaldherr.de/go/golibs/graphics" ) func main() { img := createTestImage() edgeImg := graphics.EdgeDetect(img) saveImage("edge_detect_example.png", edgeImg) fmt.Println("Edge detected image saved to edge_detect_example.png") } // createTestImage creates a simple test image func createTestImage() image.Image { img, _ := graphics.LoadImage("img.jpg") return img } // saveImage saves an image to a file func saveImage(filename string, img image.Image) { f, err := os.Create(filename) if err != nil { fmt.Println("Failed to create file:", err) return } defer f.Close() err = png.Encode(f, img) if err != nil { fmt.Println("Failed to encode image:", err) } }
Output: Edge detected image saved to edge_detect_example.png
func Edgedetect ¶ added in v0.14.0
Edgedetect detects edges in an image
func FlipHorizontal ¶ added in v0.18.0
FlipHorizontal flips an image horizontally
Example ¶
package main import ( "fmt" "image" "image/png" "os" "simonwaldherr.de/go/golibs/graphics" ) func main() { img := createTestImage() flippedImg := graphics.FlipHorizontal(img) saveImage("flip_horizontal_example.png", flippedImg) fmt.Println("Flipped image saved to flip_horizontal_example.png") } // createTestImage creates a simple test image func createTestImage() image.Image { img, _ := graphics.LoadImage("img.jpg") return img } // saveImage saves an image to a file func saveImage(filename string, img image.Image) { f, err := os.Create(filename) if err != nil { fmt.Println("Failed to create file:", err) return } defer f.Close() err = png.Encode(f, img) if err != nil { fmt.Println("Failed to encode image:", err) } }
Output: Flipped image saved to flip_horizontal_example.png
func GaussianBlur ¶ added in v0.18.0
GaussianBlur applies a Gaussian blur to an image
Example ¶
package main import ( "fmt" "image" "image/png" "os" "simonwaldherr.de/go/golibs/graphics" ) func main() { img := createTestImage() blurredImg := graphics.GaussianBlur(img) saveImage("gaussian_blur_example.png", blurredImg) fmt.Println("Gaussian blurred image saved to gaussian_blur_example.png") } // createTestImage creates a simple test image func createTestImage() image.Image { img, _ := graphics.LoadImage("img.jpg") return img } // saveImage saves an image to a file func saveImage(filename string, img image.Image) { f, err := os.Create(filename) if err != nil { fmt.Println("Failed to create file:", err) return } defer f.Close() err = png.Encode(f, img) if err != nil { fmt.Println("Failed to encode image:", err) } }
Output: Gaussian blurred image saved to gaussian_blur_example.png
func Grayscale ¶ added in v0.14.0
Grayscale converts an image to grayscale
Example ¶
package main import ( "fmt" "image" "image/png" "os" "simonwaldherr.de/go/golibs/graphics" ) func main() { img := createTestImage() grayImg := graphics.Grayscale(img) saveImage("grayscale_example.png", grayImg) fmt.Println("Grayscale image saved to grayscale_example.png") } // createTestImage creates a simple test image func createTestImage() image.Image { img, _ := graphics.LoadImage("img.jpg") return img } // saveImage saves an image to a file func saveImage(filename string, img image.Image) { f, err := os.Create(filename) if err != nil { fmt.Println("Failed to create file:", err) return } defer f.Close() err = png.Encode(f, img) if err != nil { fmt.Println("Failed to encode image:", err) } }
Output: Grayscale image saved to grayscale_example.png
func Invert ¶ added in v0.15.0
Invert inverts an image
Example ¶
package main import ( "fmt" "image" "image/png" "os" "simonwaldherr.de/go/golibs/graphics" ) func main() { img := createTestImage() invertedImg, _ := graphics.Invert(img) saveImage("invert_example.png", invertedImg) fmt.Println("Inverted image saved to invert_example.png") } // createTestImage creates a simple test image func createTestImage() image.Image { img, _ := graphics.LoadImage("img.jpg") return img } // saveImage saves an image to a file func saveImage(filename string, img image.Image) { f, err := os.Create(filename) if err != nil { fmt.Println("Failed to create file:", err) return } defer f.Close() err = png.Encode(f, img) if err != nil { fmt.Println("Failed to encode image:", err) } }
Output: Inverted image saved to invert_example.png
func NearestNeighbor ¶ added in v0.14.0
NearestNeighbor resizes an image using the nearest neighbor algorithm
func ResizeNearestNeighbor ¶
ResizeNearestNeighbor resizes an image using the nearest neighbor algorithm
func Rotate90 ¶ added in v0.18.0
Rotate90 rotates an image 90 degrees clockwise
Example ¶
package main import ( "fmt" "image" "image/png" "os" "simonwaldherr.de/go/golibs/graphics" ) func main() { img := createTestImage() rotatedImg := graphics.Rotate90(img) saveImage("rotate90_example.png", rotatedImg) fmt.Println("Rotated image saved to rotate90_example.png") } // createTestImage creates a simple test image func createTestImage() image.Image { img, _ := graphics.LoadImage("img.jpg") return img } // saveImage saves an image to a file func saveImage(filename string, img image.Image) { f, err := os.Create(filename) if err != nil { fmt.Println("Failed to create file:", err) return } defer f.Close() err = png.Encode(f, img) if err != nil { fmt.Println("Failed to encode image:", err) } }
Output: Rotated image saved to rotate90_example.png
func Sepia ¶ added in v0.18.0
Sepia applies a sepia tone to an image
Example ¶
package main import ( "fmt" "image" "image/png" "os" "simonwaldherr.de/go/golibs/graphics" ) func main() { img := createTestImage() sepiaImg := graphics.Sepia(img) saveImage("sepia_example.png", sepiaImg) fmt.Println("Sepia image saved to sepia_example.png") } // createTestImage creates a simple test image func createTestImage() image.Image { img, _ := graphics.LoadImage("img.jpg") return img } // saveImage saves an image to a file func saveImage(filename string, img image.Image) { f, err := os.Create(filename) if err != nil { fmt.Println("Failed to create file:", err) return } defer f.Close() err = png.Encode(f, img) if err != nil { fmt.Println("Failed to encode image:", err) } }
Output: Sepia image saved to sepia_example.png
func Sharpen ¶ added in v0.18.0
Sharpen applies a sharpening filter to an image
Example ¶
package main import ( "fmt" "image" "image/png" "os" "simonwaldherr.de/go/golibs/graphics" ) func main() { img := createTestImage() sharpenedImg := graphics.Sharpen(img) saveImage("sharpen_example.png", sharpenedImg) fmt.Println("Sharpened image saved to sharpen_example.png") } // createTestImage creates a simple test image func createTestImage() image.Image { img, _ := graphics.LoadImage("img.jpg") return img } // saveImage saves an image to a file func saveImage(filename string, img image.Image) { f, err := os.Create(filename) if err != nil { fmt.Println("Failed to create file:", err) return } defer f.Close() err = png.Encode(f, img) if err != nil { fmt.Println("Failed to encode image:", err) } }
Output: Sharpened image saved to sharpen_example.png
func Threshold ¶ added in v0.15.0
Threshold thresholds an image
Example ¶
package main import ( "fmt" "image" "image/png" "os" "simonwaldherr.de/go/golibs/graphics" ) func main() { img := createTestImage() threshImg := graphics.Threshold(img, 128) saveImage("threshold_example.png", threshImg) fmt.Println("Thresholded image saved to threshold_example.png") } // createTestImage creates a simple test image func createTestImage() image.Image { img, _ := graphics.LoadImage("img.jpg") return img } // saveImage saves an image to a file func saveImage(filename string, img image.Image) { f, err := os.Create(filename) if err != nil { fmt.Println("Failed to create file:", err) return } defer f.Close() err = png.Encode(f, img) if err != nil { fmt.Println("Failed to encode image:", err) } }
Output: Thresholded image saved to threshold_example.png
Types ¶
This section is empty.