std/image
Images: PNG read and written, resized, and made into the icons each
system wants. An Image is RGBA, 8 bits a channel, not premultiplied,
rows from the top; img.pixels holds them, and img.get(x, y) and
img.set(x, y, r, g, b, a) read and write one. PNG's deflate is
std/compress's, so a program that imports std/image links with zlib.
import "std/image"
Image logo = read_png("logo.png")?
write_png("logo-32.png", resize(logo, 32, 32))?
write_bytes("app.ico", encode_ico(icon_sizes(logo, ICO_SIZES)))
write_bytes("app.icns", encode_icns(icon_sizes(logo, ICNS_SIZES)))| Function | Result |
|---|---|
decode_png(data), read_png(path) |
the image of a PNG in any of its forms: grayscale, RGB, palette, with alpha or a transparent color, 1 to 16 bits, interlaced or not; an ERROR of kind "invalid_image" for data that is not PNG, a chunk whose CRC is wrong, or pixels that are not what the header says, and of kind "too_large" past IMAGE_MAX_PIXELS |
encode_png(img, level), write_png(path, img) |
RGBA PNG, each row with the filter that makes it smallest |
new_image(width, height) |
a transparent image |
resize(img, width, height, filter) |
the image at a new size, with one of RESIZE_FILTERS: "lanczos" (the default), "bicubic", "bilinear", or "box"; colors are weighted by alpha, so transparent pixels leave no fringe |
square(img) |
the image centered on a transparent square |
icon_sizes(img, sizes) |
the image, square, at each size: ICO_SIZES, ICNS_SIZES, or HICOLOR_SIZES |
encode_ico(images), decode_ico(data) |
a Windows icon of PNG images; reading takes the 24-bit and 32-bit bitmaps of older icons too |
encode_icns(images), decode_icns(data) |
a macOS icon, each size as PNG, with the Retina types of twice the size |