painter

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2024 License: MIT Imports: 11 Imported by: 4

README

🎨 Painter (WIP)

A simple utility Golang package to help you with drawing on images

This package is currently work-in-progress and subject to change at any time.

Installation

$ go get github.com/haashemi/painter@main

Example

There are some examples in the examples folder, but here is one of them.

package main

import (
	"image/color"
	"math"

	"github.com/haashemi/painter"
)

func main() {
	img := painter.New(width, height)

	black := color.NRGBA{0, 0, 0, 255}
	white := color.NRGBA{255, 255, 255, 255}

	painter.DrawLinearGradient(img, img.Rect, math.Pi/4, black, white)

	painter.SavePNG(img, "painter.png")
}

Contributions

All type of contributions are highly appreciated. <3

Documentation

Overview

Painter is a simple image.NRGBA utility packages which helps you with drawing on images.

Index

Constants

This section is empty.

Variables

View Source
var Workers int = runtime.NumCPU()

Workers defines the goroutines count used for some methods like Draw.

Functions

func Decode added in v0.1.0

func Decode(r io.Reader) (image.Image, error)

Decode calls the image.Decode and returns the image.

It's useful when you're not sure about the image type and also want to be safe from it.

func Draw added in v0.1.0

func Draw(img *image.NRGBA, rect image.Rectangle, process PixelProcessor)

Draw is a low-level method which loops through each pixel in rect's range concurrently and sets the merged & processed color on them.

func DrawColor added in v0.1.0

func DrawColor(img *image.NRGBA, rect image.Rectangle, c color.NRGBA)

DrawColor replaces each pixel's color with the specified color c. It fully takes care of transparent colors.

func DrawLinearGradient added in v0.1.0

func DrawLinearGradient(img *image.NRGBA, rect image.Rectangle, angle float64, startColor, endColor color.NRGBA)

LinearGradient draws a linear gradient on the image from startColor to endColor with in the passed angle in radians. It fully takes care of transparent colors.

func DrawRadialGradient added in v0.1.0

func DrawRadialGradient(img *image.NRGBA, rect image.Rectangle, startColor, endColor color.NRGBA, center image.Point)

DrawRadialGradient draws a radial gradient on the image from startColor to endColor. startColor starts from provided center point. It fully takes care of transparent colors.

func MergeColors added in v0.1.0

func MergeColors(background, foreground color.NRGBA) color.NRGBA

MergeNRGBA merges two image/color.NRGBA colors.

func MixNRGBA added in v0.1.0

func MixNRGBA(a float64, x, y color.NRGBA) color.NRGBA

MixNRGBA merges two colors with the provided alpha.

"a" should be between 0 and 1.

TODO: Support multiple colors

func New

func New(width, height int) *image.NRGBA

New returns a new image.NRGBA in the specified width and height.

func Paste added in v0.1.0

func Paste(dst *image.NRGBA, src image.Image, x, y int)

func SaveJPEG

func SaveJPEG(img image.Image, path string, o *jpeg.Options) error

SaveJPEG creates a file in the specified path and encodes the image as jpeg to it.

func SavePNG

func SavePNG(img image.Image, path string) error

SavePNG creates a file in the specified path and encodes the image as png to it.

Types

type PixelProcessor added in v0.1.0

type PixelProcessor func(x, y int) color.NRGBA

PixelProcessor returns a image/color.NRGBA for the specified image coordinates. It will be called concurrently.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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