pixelart

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2022 License: CC0-1.0 Imports: 11 Imported by: 0

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/pixelartexchange/artbase.server/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 CryptoPunksDev 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 added in v0.0.5

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 added in v0.0.5

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 added in v0.0.5

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 added in v0.0.5

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

func MakeImage added in v0.0.5

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

func NewImage added in v0.0.5

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 added in v0.0.5

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

func (*Image) Circle added in v0.0.5

func (tile *Image) Circle() *Image

func (*Image) Export added in v0.0.5

func (tile *Image) Export() string

func (*Image) Mirror added in v0.0.5

func (tile *Image) Mirror() *Image

func (*Image) Paste added in v0.0.5

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

func (*Image) Resize added in v0.0.5

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

func (*Image) Save added in v0.0.5

func (tile *Image) Save(path string)

func (*Image) Silhouette added in v0.0.5

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

func (*Image) ToSVG added in v0.0.5

func (tile *Image) ToSVG() string

func (*Image) Transparent added in v0.0.5

func (tile *Image) Transparent() *Image

func (*Image) Ukraine added in v0.0.5

func (tile *Image) Ukraine() *Image

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

func (*Image) Zoom added in v0.0.5

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 added in v0.0.5

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

func ReadImageComposite

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

func (*ImageComposite) Add added in v0.0.5

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

func (*ImageComposite) Max

func (composite *ImageComposite) Max() int

func (*ImageComposite) Strip added in v0.0.5

func (composite *ImageComposite) Strip() *Image

func (*ImageComposite) Tile

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

type Point added in v0.0.5

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