pixelart

package
v0.0.0-...-aa63200 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2022 License: CC0-1.0 Imports: 11 Imported by: 7

README

pixelart Package

Let's You Read and Write Pixel Art Images in the Portable Network Graphics (PNG) Format Including Support for Composites and Special Effects (Mirror, Zoom, Flip, etc.) and More

Example:

package main


import (
  "fmt"
  "github.com/learnpixelart/pixelart.go/pixelart"
)


var dir = "../basic"


func main() {
  fmt.Printf( "Hello, Pixel Art v%s!\n", pixelart.Version )

  ///////////
  // read in f(emale) attributes
  female2        := pixelart.ReadImage( dir + "/female2.png" )
  earring        := pixelart.ReadImage( dir + "/f/earring.png" )
  blondebob      := pixelart.ReadImage( dir + "/f/blondebob.png" )
  greeneyeshadow := pixelart.ReadImage( dir + "/f/greeneyeshadow.png" )

  // test drive
  // generate punk #0
  punk := pixelart.NewImage( 24, 24 )
  punk.Paste( female2 )
  punk.Paste( earring )
  punk.Paste( blondebob )
  punk.Paste( greeneyeshadow )

  punk.Save( "./punk0.png" )
  punk.Zoom(20).Save( "./punk0@20x.png" )

  // (re)try with background
  punk = pixelart.NewImage( 24, 24 ).Background( "#60A4F7" )
  punk.Paste( female2 )
  punk.Paste( earring )
  punk.Paste( blondebob )
  punk.Paste( greeneyeshadow )

  punk.Save( "./bluepunk0.png" )
  punk.Zoom(20).Save( "./bluepunk0@20x.png" )


  ///////////
  // read in m(ale) attributes
  male1   := pixelart.ReadImage( dir + "/male1.png" )
  smile   := pixelart.ReadImage( dir + "/m/smile.png" )
  mohawk  := pixelart.ReadImage( dir + "/m/mohawk.png" )

  // generate punk #1
  punk = pixelart.NewImage( 24, 24 )
  punk.Paste( male1 )
  punk.Paste( smile )
  punk.Paste( mohawk )

  punk.Save( "./punk1.png" )
  punk.Zoom(20).Save( "./punk1@20x.png" )

  // (re)try with background
  punk = pixelart.NewImage( 24, 24 ).Background( "#60A4F7" )
  punk.Paste( male1 )
  punk.Paste( smile )
  punk.Paste( mohawk )

  punk.Save( "./bluepunk1.png" )
  punk.Zoom(20).Save( "./bluepunk1@20x.png" )

  fmt.Println( "Bye")
}

For more see Let's Go! Programming (Crypto) Pixel Punk Profile Pictures & (Generative) Art with Go - Step-by-Step Book / Guide »

Questions? Comments?

Yes, you can. Post them on the D.I.Y. Punk (Pixel) Art reddit. Thanks.

Documentation

Index

Constants

View Source
const Version = "0.1.0-20220406"

Variables

View Source
var ColorMap = map[string]color.RGBA{}/* 153 elements not displayed */

Functions

func ConvertToNRGBA

func ConvertToNRGBA(img image.Image) *image.NRGBA

see https://stackoverflow.com/questions/61964247/idiomatic-go-for-handling-any-image-type-with-any-color-type

https://stackoverflow.com/questions/47535474/convert-image-from-image-ycbcr-to-image-rgba

func Download

func Download(url, outpath string)

func MakeColor

func MakeColor(a interface{}) color.Color

todo - find a better name - ensureColor/safeColor or ? - why? why not?

func ParseColor

func ParseColor(s string) (color.RGBA, error)

func ParseHexColor

func ParseHexColor(s string) (c color.RGBA, err error)

func ToByte

func ToByte(data []uint32) []byte

Types

type ColorInfo

type ColorInfo struct {
	Count int // no. of pixels
	Index int // zero-based running index (0,1,2, etc.)
}

todo/check: find a better name - why? why not?

type Image

type Image struct {
	*image.NRGBA // use "composition" - for "nicer"  api (lets you use like image.Image) - why? why not?
}

func MakeImage

func MakeImage(pix []uint32, imageSize *image.Point) *Image

func NewImage

func NewImage(width, height int) *Image

todo - move to ImageTitle.go file - why? why not?

func ReadImage

func ReadImage(path string) *Image

func (*Image) Background

func (tile *Image) Background(background_any interface{}) *Image

func (*Image) Circle

func (tile *Image) Circle() *Image

func (*Image) Export

func (tile *Image) Export() string

func (*Image) Mirror

func (tile *Image) Mirror() *Image

func (*Image) Paste

func (tile *Image) Paste(img image.Image)

func (*Image) Resize

func (tile *Image) Resize(width int) *Image

func (*Image) Save

func (tile *Image) Save(path string)

func (*Image) Silhouette

func (tile *Image) Silhouette(foreground_any interface{}) *Image

func (*Image) ToSVG

func (tile *Image) ToSVG() string

func (*Image) Transparent

func (tile *Image) Transparent() *Image

func (*Image) Ukraine

func (tile *Image) Ukraine() *Image

draw flag of ukraine -- glory to ukraine! fuck (vladimir) putin! stop the war!

func (*Image) Zoom

func (tile *Image) Zoom(zoom int) *Image

type ImageComposite

type ImageComposite struct {
	Image                 // use "composition" - note: does NOT use image.Image but our own!!!
	TileWidth, TileHeight int
	Count                 int // optional - not all tiles (full cap(acity) might be used)
}

func NewImageComposite

func NewImageComposite(cols int, rows int,
	tileSize *image.Point) *ImageComposite

func ReadImageComposite

func ReadImageComposite(path string, tileSize *image.Point) *ImageComposite

func (*ImageComposite) Add

func (composite *ImageComposite) Add(tile image.Image)

func (*ImageComposite) Max

func (composite *ImageComposite) Max() int

func (*ImageComposite) Strip

func (composite *ImageComposite) Strip() *Image

func (*ImageComposite) Tile

func (composite *ImageComposite) Tile(id int) *Image

type Point

type Point = image.Point

for convenience add a type alias for image.Point

Jump to

Keyboard shortcuts

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