image

package module
v0.0.0-...-390438e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 11, 2022 License: MIT Imports: 10 Imported by: 0

README

image

Package image implements a simple library for image operations. The library can work with pngs or jpgs. Same functions can be used for both of those image types.

Read more here: http://www.koraygocmen.com/blog/writing-an-image-manipulation-library-in-go-part-1

98% Test coverage


Full Documentation:

https://godoc.org/github.com/KorayGocmen/image

package main

import (
	"fmt"
	"log"

	"github.com/koraygocmen/image"
)

func main() {
	img, _ := image.New("test/test.jpg")

	err1 := img.Grayscale(image.GrayscaleAverage).WriteToFile("test/grayscale_average_method.jpg")
	if err1 != nil {
		log.Fatal(err1)
	}

	err2 := img.Grayscale(image.GrayscaleDesaturation).WriteToFile("test/grayscale_saturation_method.jpg")
	if err2 != nil {
		log.Fatal(err2)
	}

	err3 := img.Grayscale(image.GrayscaleLuma).WriteToFile("test/grayscale_luma_method.jpg")
	if err3 != nil {
		log.Fatal(err3)
	}

	err4 := img.Filter("R", 2).WriteToFile("test/red_color_filtered_200_percent.jpg")
	if err4 != nil {
		log.Fatal(err4)
	}

	// Works both with pngs and jpgs.
	imgPng, _ := image.New("test/test.png")
	fmt.Println(imgPng.Height, imgPng.Width)
}


License

Released under the MIT License.

Documentation

Overview

Package image implements a simple library for image operations. The library can work with pngs or jpgs. Same functions can be used for both of those image types.

Index

Constants

View Source
const (
	GrayscaleAverage      = 0
	GrayscaleLuma         = 1
	GrayscaleDesaturation = 2
)

GrayscaleAverage, GrayscaleLuma, GrayscaleDesaturation are used by grayscale to choose between algorithms

Variables

This section is empty.

Functions

This section is empty.

Types

type Image

type Image struct {
	Pixels [][]Pixel
	Width  int
	Height int
	// contains filtered or unexported fields
}

Image is the main object that holds information about the image file. Also is a wrapper around the decoded image from the standard image library.

func New

func New(filePath string) (*Image, error)

New reads an image from the given file path and return a new `Image` struct.

func RemoveMovingObj

func RemoveMovingObj(filePaths []string) (*Image, error)

RemoveMovingObj iterates the given filepaths and generates new image objects. It then checks to see if all the heights and the widths of the images are matching. If they are, each pixel of every image is iterated and a median filter is applied to given images. Returns the output image object and an error if there is any.

func (*Image) Filter

func (img *Image) Filter(color string, percentage float32) *Image

Filter with "R", "G" or "B" values. Increase the given r/g/b values of pixel by the given percentage.

func (*Image) Grayscale

func (img *Image) Grayscale(algorithm int) *Image

Grayscale turns the images to grayscale.

func (*Image) WriteToFile

func (img *Image) WriteToFile(outputPath string) error

WriteToFile writes iamges to the given filepath. Returns an error if it occurs.

type Pixel

type Pixel struct {
	R int
	G int
	B int
	A int
}

Pixel is a single pixel in 2d array

func (*Pixel) Get

func (pix *Pixel) Get(keyName string) int

Get pixel value with key name

func (*Pixel) Set

func (pix *Pixel) Set(keyName string, val int) Pixel

Set pixel value with key name and new value

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL