-
-
Notifications
You must be signed in to change notification settings - Fork 1
GalaktaGlareIMG
The galaktaglareimg
package provides a set of utilities for loading, saving, resizing, converting, and comparing images in Go. It utilizes the imaging
library from GitHub for image processing tasks. This documentation will cover the usage of each function provided by the package, along with examples and explanations.
To use the galaktaglareimg
package, you need to install the imaging
library:
go get -u github.com/disintegration/imaging
Then, you can import the package in your Go code:
import (
"image"
"image/color"
"math"
"errors"
"github.com/disintegration/imaging"
)
func LoadImage(path string) (image.Image, error)
LoadImage
loads an image from the specified file path and returns an image.Image
object. If the image cannot be loaded, it returns an error.
Parameters:
-
path
(string): The path to the image file.
Returns:
-
image.Image
: The loaded image. -
error
: An error if the image cannot be loaded.
Example:
img, err := galaktaglareimg.LoadImage("path/to/image.jpg")
if err != nil {
log.Fatal(err)
}
func SaveImage(img image.Image, path string) error
SaveImage
saves an image to the specified file path. If the image cannot be saved, it returns an error.
Parameters:
-
img
(image.Image): The image to save. -
path
(string): The path to save the image file.
Returns:
-
error
: An error if the image cannot be saved.
Example:
err := galaktaglareimg.SaveImage(img, "path/to/save/image.jpg")
if err != nil {
log.Fatal(err)
}
func ResizeImage(img image.Image, width, height int) image.Image
ResizeImage
resizes an image to the specified width and height using the Lanczos resampling method.
Parameters:
-
img
(image.Image): The image to resize. -
width
(int): The new width of the image. -
height
(int): The new height of the image.
Returns:
-
image.Image
: The resized image.
Example:
resizedImg := galaktaglareimg.ResizeImage(img, 200, 100)
func ConvertToGrayscale(img image.Image) image.Image
ConvertToGrayscale
converts an image to grayscale.
Parameters:
-
img
(image.Image): The image to convert.
Returns:
-
image.Image
: The grayscale image.
Example:
grayscaleImg := galaktaglareimg.ConvertToGrayscale(img)
func CompareImages(img1, img2 image.Image) (float64, error)
CompareImages
compares two images and returns the Peak Signal-to-Noise Ratio (PSNR). The images must have the same dimensions. If they do not, it returns an error.
Parameters:
-
img1
(image.Image): The first image to compare. -
img2
(image.Image): The second image to compare.
Returns:
-
float64
: The PSNR value indicating the similarity between the two images. -
error
: An error if the images do not have the same dimensions.
Example:
psnr, err := galaktaglareimg.CompareImages(img1, img2)
if err != nil {
log.Fatal(err)
}
fmt.Printf("PSNR: %f\n", psnr)
func ImageToGrayscaleArray(img image.Image) [][]uint8
ImageToGrayscaleArray
converts an image to a 2D array of grayscale values.
Parameters:
-
img
(image.Image): The image to convert.
Returns:
-
[][]uint8
: A 2D array of grayscale values.
Example:
grayscaleArray := galaktaglareimg.ImageToGrayscaleArray(img)
fmt.Println(grayscaleArray)
package main
import (
"log"
"github.com/simplyYan/GalaktaGlare/src/GalaktaGlareIMG"
)
func main() {
img, err := galaktaglareimg.LoadImage("path/to/image.jpg")
if err != nil {
log.Fatal(err)
}
err = galaktaglareimg.SaveImage(img, "path/to/save/image.jpg")
if err != nil {
log.Fatal(err)
}
}
package main
import (
"github.com/simplyYan/GalaktaGlare/src/GalaktaGlareIMG"
"log"
)
func main() {
img, err := galaktaglareimg.LoadImage("path/to/image.jpg")
if err != nil {
log.Fatal(err)
}
resizedImg := galaktaglareimg.ResizeImage(img, 200, 100)
err = galaktaglareimg.SaveImage(resizedImg, "path/to/save/resized_image.jpg")
if err != nil {
log.Fatal(err)
}
}
package main
import (
"github.com/simplyYan/GalaktaGlare/src/GalaktaGlareIMG"
"log"
)
func main() {
img, err := galaktaglareimg.LoadImage("path/to/image.jpg")
if err != nil {
log.Fatal(err)
}
grayscaleImg := galaktaglareimg.ConvertToGrayscale(img)
err = galaktaglareimg.SaveImage(grayscaleImg, "path/to/save/grayscale_image.jpg")
if err != nil {
log.Fatal(err)
}
}
package main
import (
"github.com/simplyYan/GalaktaGlare/src/GalaktaGlareIMG"
"log"
"fmt"
)
func main() {
img1, err := galaktaglareimg.LoadImage("path/to/image1.jpg")
if err != nil {
log.Fatal(err)
}
img2, err := galaktaglareimg.LoadImage("path/to/image2.jpg")
if err != nil {
log.Fatal(err)
}
psnr, err := galaktaglareimg.CompareImages(img1, img2)
if err != nil {
log.Fatal(err)
}
fmt.Printf("PSNR: %f\n", psnr)
}
package main
import (
"github.com/simplyYan/GalaktaGlare/src/GalaktaGlareIMG"
"log"
"fmt"
)
func main() {
img, err := galaktaglareimg.LoadImage("path/to/image.jpg")
if err != nil {
log.Fatal(err)
}
grayscaleArray := galaktaglareimg.ImageToGrayscaleArray(img)
fmt.Println(grayscaleArray)
}
This documentation provides a comprehensive overview of the galaktaglareimg
package, covering its installation, functions, and usage examples. By following these examples, users can easily incorporate image processing capabilities into their Go applications.