Image

Library including the basic tools for handling images and colors.


Source: pkg/lua/lib/image.go | Import: image

Functions


new

new(name, encoding, width, height, model?) -> int<collection.IMAGE>

Arguments

  • name string
  • encoding int<image.Encoding>
  • width int
  • height int
  • model int<image.ColorModel>
Return Values

  • int<collection.IMAGE>
new_filled

new_filled(name, encoding, width, height, color, model?) -> int<collection.IMAGE>

Arguments

  • name string
  • encoding int<image.Encoding>
  • width int
  • height int
  • color struct<image.Color>
  • model int<image.ColorModel>
Return Values

  • int<collection.IMAGE>
new_random

new_random(name, encoding, width, height, enableAlpha?, model?) -> int<collection.IMAGE>

Arguments

  • name string
  • encoding int<image.Encoding>
  • width int
  • height int
  • enableAlpha bool
  • model int<image.ColorModel>
Return Values

  • int<collection.IMAGE>
new_empty

new_empty(name, encoding) -> int<collection.IMAGE>

Creates a 1px by 1px gray image.

Arguments

  • name string
  • encoding int<image.Encoding>
Return Values

  • int<collection.IMAGE>
remove

remove(id)

Removes the image from the collection. This is a shortcut for collection.collect(collection.IMAGE, id).

Arguments

  • id int<collection.IMAGE>
name

name(id, name)

Arguments

  • id int<collection.IMAGE>
  • name string - The new name to use for the image, not including the file extension.
name_ext

name_ext(id, options)

Arguments

  • id int<collection.IMAGE>
  • options struct<image.ImageNameOptions>
encoding

encoding(id, encoding)

Arguments

  • id int<collection.IMAGE>
  • encoding int<image.Encoding>
model

model(id) -> int<image.ColorModel>

@blocking
Arguments

  • id int<collection.IMAGE>
Return Values

  • int<image.ColorModel>
size

size(id) -> int, int

@blocking
Arguments

  • id int<collection.IMAGE>
Return Values

  • int - Image width.
  • int - Image height.
crop

crop(id, x1, y1, x2, y2)

Overwrites the image.

Arguments

  • id int<collection.IMAGE>
  • x1 int
  • y1 int
  • x2 int
  • y2 int
subimg

subimg(id, name, x1, y1, x2, y2, copy?) -> int<collection.IMAGE>

Arguments

  • id int<collection.IMAGE>
  • name string - Name for the new image.
  • x1 int
  • y1 int
  • x2 int
  • y2 int
  • copy bool
Return Values

  • int<collection.IMAGE>
copy

copy(id, name, model) -> int<collection.IMAGE>

Arguments

  • id int<collection.IMAGE>
  • name string
  • model int<image.ColorModel> - Use -1 to maintain the color model.
Return Values

  • int<collection.IMAGE>
clone

clone(id, src, model)

Clones image src to id with the new model.

Arguments

  • id int<collection.IMAGE>
  • src int<collection.IMAGE>
  • model int<image.ColorModel> - Use -1 to maintain the color model.
Return Values

  • int<collection.IMAGE>
convert

convert(id, model)

Replaces the image inplace with a new image with the new model.

Arguments

  • id int<collection.IMAGE>
  • model int<image.ColorModel>
refresh

refresh(id)

Shortcut for redrawing the image to guarantee the bounds of the image start at (0,0). This is sometimes needed as thirdparty libraries don't always account for non-zero min bounds.

Arguments

  • id int<collection.IMAGE>
clear

clear(id)

Resets all pixels to 0,0,0,0.

Arguments

  • id int<collection.IMAGE>
alpha_set

alpha_set(id, alpha)

This has no effect on gray, gray16, or cmyk images.

Arguments

  • id int<collection.IMAGE>
  • alpha int
pixel

pixel(id, x, y) -> struct<image.ColorRGBA>

@blocking
Arguments

  • id int<collection.IMAGE>
  • x int
  • y int
Return Values

  • struct<image.ColorRGBA>
pixel_set

pixel_set(id, x, y, color)

Arguments

  • id int<collection.IMAGE>
  • x int
  • y int
  • color struct<image.Color>
point

point(x?, y?) -> struct<image.Point>

Arguments

  • x int
  • y int
Return Values

  • struct<image.Point>
color_hex_to_rgba

color_hex_to_rgba(hex) -> struct<image.ColorRGBA>

Arguments

  • hex string - Accepts the formats RGBA, RGB, RRGGBBAA, RRGGBB, and an optional prefix of "#", "$", or "0x".
Return Values

  • struct<image.ColorRGBA>
color_hex_to_rgba_bgr

color_hex_to_rgba_bgr(hex) -> struct<image.ColorRGBA>

Arguments

  • hex string - Accepts the formats ABGR, BGR, AABBGGRR, BBGGRR, and an optional prefix of "#", "$", or "0x".
Return Values

  • struct<image.ColorRGBA>
color_to_hex

color_to_hex(color, noalpha?, prefix?, lowercase?) -> string

In the format RRGGBBAA or RRGGBB.

Arguments

  • color struct<image.Color>
  • noalpha bool - Set to true to exclude the alpha channel.
  • prefix string - Should be "", "#", '$', or "0x".
  • lowercase bool - Set to true to use lowercase letters in the hex string.
Return Values

  • string
color_to_hex_bgr

color_to_hex_bgr(color, noalpha?, prefix?, lowercase?) -> string

In the format AABBGGRR or BBGGRR.

Arguments

  • color struct<image.Color>
  • noalpha bool - Set to true to exclude the alpha channel.
  • prefix string - Should be "", "#", '$', or "0x".
  • lowercase bool - Set to true to use lowercase letters in the hex string.
Return Values

  • string
color_8bit_to_16bit

color_8bit_to_16bit(c) -> int

Arguments

  • c int
Return Values

  • int
color_16bit_to_8bit

color_16bit_to_8bit(c) -> int

Arguments

  • c int
Return Values

  • int
color_24bit_to_rgba

color_24bit_to_rgba(c) -> struct<image.ColorRGBA>

Arguments

  • c int
Return Values

  • struct<image.ColorRGBA>
color_32bit_to_rgba

color_32bit_to_rgba(c) -> struct<image.ColorRGBA>

Arguments

  • c int
Return Values

  • struct<image.ColorRGBA>
color_to_24bit

color_to_24bit(color) -> int

Arguments

  • color struct<image.Color>
Return Values

  • int
color_to_32bit

color_to_32bit(color) -> int

Arguments

  • color struct<image.Color>
Return Values

  • int
color_rgb

color_rgb(r, g, b) -> struct<image.ColorRGBA>

Alpha channel is set to 255.

Arguments

  • r int
  • g int
  • b int
Return Values

  • struct<image.ColorRGBA>
color_rgba

color_rgba(r, g, b, a) -> struct<image.ColorRGBA>

Arguments

  • r int
  • g int
  • b int
  • a int
Return Values

  • struct<image.ColorRGBA>
color_hsv

color_hsv(h, s, v) -> struct<image.ColorHSVA>

Alpha channel is set to 255.

Arguments

  • h int
  • s int
  • v int
Return Values

  • struct<image.ColorHSVA>
color_hsva

color_hsva(h, s, v, a) -> struct<image.ColorHSVA>

Arguments

  • h int
  • s int
  • v int
  • a int
Return Values

  • struct<image.ColorHSVA>
color_hsl

color_hsl(h, s, l) -> struct<image.ColorHSLA>

Alpha channel is set to 255.

Arguments

  • h int
  • s int
  • l int
Return Values

  • struct<image.ColorHSLA>
color_hsla

color_hsla(h, s, l, a) -> struct<image.ColorHSLA>

Arguments

  • h int
  • s int
  • l int
  • a int
Return Values

  • struct<image.ColorHSLA>
color_alpha

color_alpha(a) -> struct<image.ColorALPHA>

Arguments

  • a int
Return Values

  • struct<image.ColorALPHA>
color_alpha16

color_alpha16(a) -> struct<image.ColorALPHA16>

Arguments

  • a int
Return Values

  • struct<image.ColorALPHA16>
color_gray

color_gray(v) -> struct<image.ColorGRAY>

Arguments

  • v int
Return Values

  • struct<image.ColorGRAY>
color_gray16

color_gray16(v) -> struct<image.ColorGRAY16>

Arguments

  • v int
Return Values

  • struct<image.ColorGRAY16>
color_graya

color_graya(v, a) -> struct<image.ColorGRAYA>

Arguments

  • v int
  • a int
Return Values

  • struct<image.ColorGRAYA>
color_graya16

color_graya16(v, a) -> struct<image.ColorGRAYA16>

Arguments

  • v int
  • a int
Return Values

  • struct<image.ColorGRAYA16>
color_cmyk

color_cmyk(c, m, y, k) -> struct<image.ColorCMYK>

Arguments

  • c int
  • m int
  • y int
  • k int
Return Values

  • struct<image.ColorCMYK>
color_cmyka

color_cmyka(c, m, y, k, a) -> struct<image.ColorCMYKA>

Arguments

  • c int
  • m int
  • y int
  • k int
  • a int
Return Values

  • struct<image.ColorCMYKA>
color_zero

color_zero() -> struct<image.ColorZERO>

Return Values

  • struct<image.ColorZERO>
color_to_rgb

color_to_rgb(color) -> struct<image.ColorRGBA>

Alpha is maintained.

Arguments

  • color struct<image.Color>
Return Values

  • struct<image.ColorRGBA>
color_to_hsv

color_to_hsv(color) -> struct<image.ColorHSVA>

Alpha is maintained.

Arguments

  • color struct<image.Color>
Return Values

  • struct<image.ColorHSVA>
color_to_hsl

color_to_hsl(color) -> struct<image.ColorHSLA>

Alpha is maintained.

Arguments

  • color struct<image.Color>
Return Values

  • struct<image.ColorHSLA>
color_to_gray

color_to_gray(color) -> struct<image.ColorGRAY>

Arguments

  • color struct<image.Color>
Return Values

  • struct<image.ColorGRAY>
color_to_gray_average

color_to_gray_average(color) -> struct<image.ColorGRAY>

Arguments

  • color struct<image.Color>
Return Values

  • struct<image.ColorGRAY>
color_to_gray_weight

color_to_gray_weight(color, rWeight, gWeight, bWeight) -> struct<image.ColorGRAY>

Arguments

  • color struct<image.Color>
  • rWeight int
  • gWeight int
  • bWeight int
Return Values

  • struct<image.ColorGRAY>
color_to_graya

color_to_graya(color) -> struct<image.ColorGRAYA>

Alpha is maintained.

Arguments

  • color struct<image.Color>
Return Values

  • struct<image.ColorGRAYA>
color_to_graya_average

color_to_graya_average(color) -> struct<image.ColorGRAYA>

Alpha is maintained.

Arguments

  • color struct<image.Color>
Return Values

  • struct<image.ColorGRAYA>
color_to_graya_weight

color_to_graya_weight(color, rWeight, gWeight, bWeight) -> struct<image.ColorGRAYA>

Alpha is maintained.

Arguments

  • color struct<image.Color>
  • rWeight int
  • gWeight int
  • bWeight int
Return Values

  • struct<image.ColorGRAYA>
color_to_graya16

color_to_graya16(color) -> struct<image.ColorGRAYA16>

Alpha is maintained.

Arguments

  • color struct<image.Color>
Return Values

  • struct<image.ColorGRAYA16>
color_to_graya16_average

color_to_graya16_average(color) -> struct<image.ColorGRAYA16>

Alpha is maintained.

Arguments

  • color struct<image.Color>
Return Values

  • struct<image.ColorGRAYA16>
color_to_graya16_weight

color_to_graya16_weight(color, rWeight, gWeight, bWeight) -> struct<image.ColorGRAYA16>

Alpha is maintained.

Arguments

  • color struct<image.Color>
  • rWeight int
  • gWeight int
  • bWeight int
Return Values

  • struct<image.ColorGRAYA16>
color_to_alpha

color_to_alpha(color) -> struct<image.ColorALPHA>

Arguments

  • color struct<image.Color>
Return Values

  • struct<image.ColorALPHA>
color_to_alpha16

color_to_alpha16(color) -> struct<image.ColorALPHA16>

Arguments

  • color struct<image.Color>
Return Values

  • struct<image.ColorALPHA16>
color_to_cmyk

color_to_cmyk(color) -> struct<image.ColorCMYK>

Arguments

  • color struct<image.Color>
Return Values

  • struct<image.ColorCMYK>
color_to_cmyka

color_to_cmyka(color) -> struct<image.ColorCMYKA>

Arguments

  • color struct<image.Color>
Return Values

  • struct<image.ColorCMYKA>
convert_color

convert_color(model, color) -> struct<image.ColorRGBA>

Arguments

  • model int<image.ColorModel>
  • color struct<image.Color>
Return Values

  • struct<image.ColorRGBA>
draw

draw(id, src, x, y, width?, height?)

Arguments

  • id int<collection.IMAGE>
  • src int<collection.IMAGE> - To draw onto the base image.
  • x int
  • y int
  • width int
  • height int
map

map(id, fn, invert?)

Arguments

  • id int<collection.IMAGE>
  • fn function(x int, y int, color struct<image.ColorRGBA>) -> struct<image.Color>
  • invert bool - Reverses the looping order from columns to rows.
compare

compare(id1, id2) -> bool

@blocking

Compares two images pixel by pixel. Early returns if the image ids are the same, without scheduling any tasks.

Arguments

  • id1 int<collection.IMAGE>
  • id2 int<collection.IMAGE>
Return Values

  • bool
ext_to_encoding

ext_to_encoding(ext) -> int<image.Encoding>

Arguments

  • ext string
Return Values

  • int<image.Encoding>
path_to_encoding

path_to_encoding(pth) -> int<image.Encoding>

First gets the ext from the path.

Arguments

  • pth string
Return Values

  • int<image.Encoding>
encoding_to_ext

encoding_to_ext(encoding) -> string

Arguments

  • encoding int<image.Encoding>
Return Values

  • string
extract_colors

extract_colors(img) -> []struct<image.ColorRGBA>

@blocking
Arguments

  • img int<collection.IMAGE>
Return Values

  • []struct<image.ColorRGBA>
extract_colors_config

extract_colors_config(img, downSizeTo, smallBucket) -> []struct<image.ColorRGBA>

@blocking
Arguments

  • img int<collection.IMAGE>
  • downSizeTo float
  • smallBucket float
Return Values

  • []struct<image.ColorRGBA>
png_data_chunk

png_data_chunk(key, data) -> struct<image.PNGDataChunk>

Arguments

  • key string
  • data string
Return Values

  • struct<image.PNGDataChunk>
gif

gif(imgs, delay, loopCount, disposal?, backgroundIndex?) -> struct<image.GIF>

Arguments

  • imgs []int<collection.IMAGE>
  • delay []int
  • loopCount int
  • disposal []int<image.GIFDisposal>
  • backgroundIndex int
Return Values

  • struct<image.GIF>

Constants


ColorModel
  • MODEL_RGBA
  • MODEL_RGBA64
  • MODEL_NRGBA
  • MODEL_NRGBA64
  • MODEL_ALPHA
  • MODEL_ALPHA16
  • MODEL_GRAY
  • MODEL_GRAY16
  • MODEL_CMYK
Encoding
  • ENCODING_PNG
  • ENCODING_JPEG
  • ENCODING_GIF
  • ENCODING_TIFF
  • ENCODING_BMP
  • ENCODING_ICO
  • ENCODING_CUR
ColorType
  • COLOR_TYPE_RGBA
  • COLOR_TYPE_HSVA
  • COLOR_TYPE_HSLA
  • COLOR_TYPE_GRAY
  • COLOR_TYPE_GRAY16
  • COLOR_TYPE_GRAYA
  • COLOR_TYPE_GRAYA16
  • COLOR_TYPE_ALPHA
  • COLOR_TYPE_ALPHA16
  • COLOR_TYPE_CMYK
  • COLOR_TYPE_CMYKA
  • COLOR_TYPE_ZERO
GIFDisposal
  • GIFDISPOSAL_NONE
  • GIFDISPOSAL_BACKGROUND
  • GIFDISPOSAL_PREVIOUS
WebPPreset
  • WEBPPRESET_DEFAULT
  • WEBPPRESET_PICTURE
  • WEBPPRESET_PHOTO
  • WEBPPRESET_DRAWING
  • WEBPPRESET_ICON
  • WEBPPRESET_TEXT

Structs


ImageNameOptions

Properties

  • name string
  • prefix string
  • suffix string
Point

Properties

  • x int
  • y int
ColorRGBA

Properties

  • type string<image.ColorType>
  • red int
  • green int
  • blue int
  • alpha int
ColorHSVA

Properties

  • type string<image.ColorType>
  • hue int
  • sat int
  • value int
  • alpha int
ColorHSLA

Properties

  • type string<image.ColorType>
  • hue int
  • light int
  • value int
  • alpha int
ColorALPHA

Properties

  • type string<image.ColorType>
  • alpha int
ColorALPHA16

Properties

  • type string<image.ColorType>
  • alpha int
ColorGRAY

Properties

  • type string<image.ColorType>
  • gray int
ColorGRAY16

Properties

  • type string<image.ColorType>
  • gray int
ColorGRAYA

Properties

  • type string<image.ColorType>
  • gray int
  • alpha int
ColorGRAYA16

Properties

  • type string<image.ColorType>
  • gray int
  • alpha int
ColorCMYK

Properties

  • type string<image.ColorType>
  • cyan int
  • magenta int
  • yellow int
  • key int
ColorCMYKA

Properties

  • type string<image.ColorType>
  • cyan int
  • magenta int
  • yellow int
  • key int
  • alpha int
ColorZERO

Properties

  • type string<image.ColorType>
PNGDataChunk

Properties

  • key string
  • data string
GIF

Properties

  • img []int<collection.IMAGE>
  • delay []int
  • disposal []int<image.GIFDisposal>
  • loop_count int
  • background_index int

Interfaces


Color

Color structs are automatically converted into the needed type. Do mind that some functions may return a different type than what was passed into it.

Properties

  • type string<image.ColorType>