image
Reading, editing and saving images, and writing text on them.
import image
This package works with images without any outside library: it reads and writes PNG, JPEG and BMP. It also reads and writes WebP, both lossy and lossless. From a GIF it reads the first frame, and it saves an image in a GIF with at most 256 colors. Open and Save work the format out from the content or the extension. Drawing, resizing, cropping, rotating and filters such as blurring and sharpening are all there.
For text, read a TrueType font with LoadFont and write with DrawTextStyled; Persian and Arabic text is shaped and laid out right to left on its own. For building social media images automatically, DrawTextFitBox finds the size that fits. The font example needs a font file and on the site it is only checked.
Types
Image
struct Image| Name | Type | Description |
|---|---|---|
width | int = 0 | The width in pixels. |
height | int = 0 | The height. |
pixels | void* | The pixels, four bytes each, row by row. |
import image
import os
func main:
mut img := image.New(8, 6)
println img.width, img.height, image.IsEmpty(img), image.InBounds(img, 7, 5), image.InBounds(img, 8, 0)
image.Fill(img, image.RGB(255, 255, 255))
image.FillHex(img, "#202040")
image.SetPixel(img, 0, 0, image.RGB(255, 0, 0))
image.BlendPixel(img, 1, 0, image.RGBA(255, 255, 255, 128))
println image.ToHex(image.GetPixel(img, 0, 0)), image.ToHex(image.GetPixel(img, 1, 0)), image.ToHexRGB(image.GetPixel(img, 2, 0))
image.DrawLine(img, 0, 5, 7, 5, image.Gray(200))
image.DrawRect(img, 1, 1, 4, 3, image.ParseHex("#ffcc00"))
image.DrawRectFilled(img, 2, 2, 2, 1, image.ParseHex("#00ff00"))
image.DrawCircle(img, 6, 2, 1, image.Gray(255))
image.DrawCircleFilled(img, 6, 2, 0, image.Gray(10))
println image.ToHexRGB(image.GetPixel(img, 3, 2)), image.ToHexRGB(image.GetPixel(img, 4, 5))
color := image.ParseHex("#336699")
println color.r, color.g, color.b, color.a, image.Luminance(color)
println image.Equals(color, image.RGB(51, 102, 153)), image.ToHex(image.Blend(color, image.RGBA(255, 255, 255, 0)))
println image.ToHexRGB(image.LerpColor(image.Gray(0), image.Gray(200), 0.5))
mut labelled := image.NewFilled(40, 10, image.Gray(0))
image.DrawText(labelled, 1, 1, "SALAM", image.Gray(255), 1)
println image.TextWidth("SALAM", 1), image.FontWidth, image.FontHeight
dir := os.TempDir()
println image.Save(img, dir + "/salam_en.png"), image.SavePNG(img, dir + "/salam2_en.png"), image.SaveBMP(img, dir + "/salam_en.bmp"), image.SaveJPEG(img, dir + "/salam_en.jpg", 90)
println image.SaveQuality(img, dir + "/salam2_en.jpg", 50), image.SaveWebP(img, dir + "/salam_en.webp")
mut ok := false
read := image.Open(dir + "/salam_en.png", ok)
println ok, read.width, image.Equals(image.GetPixel(read, 0, 0), image.GetPixel(img, 0, 0))
png := image.OpenPNG(dir + "/salam2_en.png", ok)
bmp := image.OpenBMP(dir + "/salam_en.bmp", ok)
jpg := image.OpenJPEG(dir + "/salam_en.jpg", ok)
println ok, png.width, bmp.height, jpg.width
println image.FormatFromExt("a.jpeg") == image.FormatJPEG, image.FormatFromExt("a.png") == image.FormatPNG, image.FormatFromExt("a.txt") == image.FormatUnknown
buf := image.EncodePNG(img)
println image.DetectFormat(buf.data, buf.len) == image.FormatPNG, image.IsWebP(buf.data, buf.len)
from_buf := image.DecodePNG(buf.data, buf.len, ok)
generic := image.Decode(buf.data, buf.len, ok)
println ok, from_buf.width, generic.height
b := image.EncodeBMP(img)
b2 := image.DecodeBMP(b.data, b.len, ok)
j := image.EncodeJPEG(img, 80)
j2 := image.DecodeJPEG(j.data, j.len, ok)
println image.DetectFormat(b.data, b.len) == image.FormatBMP, image.DetectFormat(j.data, j.len) == image.FormatJPEG, b2.width, j2.width
any := image.Encode(img, image.FormatBMP, 90)
web := image.EncodeWebP(img)
lossy := image.EncodeWebPQuality(img, 75)
println any.len == b.len, web.len > 0, image.FormatWebP
clear := image.NewFilled(1, 1, image.RGBA(0, 0, 0, 0))
println image.ToHex(image.GetPixel(image.FlattenAlpha(clear, image.Gray(255)), 0, 0))
converted := image.Convert(img, image.FormatJPEG)
println converted.width
webp := image.DecodeWebP(web.data, web.len, ok)
println ok, webp.width, image.Equals(image.GetPixel(webp, 1, 0), image.GetPixel(img, 1, 0))
webp3 := image.DecodeWebP(lossy.data, lossy.len, ok)
println ok, webp3.width, webp3.height
webp2 := image.OpenWebP(dir + "/salam_en.webp", ok)
println image.SaveGIF(img, dir + "/salam_en.gif"), image.FormatFromExt("a.gif") == image.FormatGIF
gif := image.OpenGIF(dir + "/salam_en.gif", ok)
g := image.EncodeGIF(img)
gif2 := image.DecodeGIF(g.data, g.len, ok)
println ok, gif.width, gif2.height, image.IsGIF(g.data, g.len), image.Equals(image.GetPixel(gif, 0, 0), image.GetPixel(img, 0, 0))
println ok, webp2.height
mut copy := image.Clone(img)
image.Free(copy)
image.Free(img)
endColor
struct Color| Name | Type | Description |
|---|---|---|
r | u8 = 0 | Red, 0 to 255. |
g | u8 = 0 | Green. |
b | u8 = 0 | Blue. |
a | u8 = 255 | Alpha, that is opacity; 255 is fully opaque. |
The example for this item is shown with the ones above: image-Draw.salam
Font
struct Font| Name | Type | Description |
|---|---|---|
data | void* | The file's bytes. |
size | int = 0 | The size of the data. |
units_per_em | int = 0 | The units per em. |
num_glyphs | int = 0 | The number of glyphs. |
ascent | int = 0 | The ascent. |
descent | int = 0 | The descent. |
line_gap | int = 0 | The line gap. |
glyf | int = 0 | Where the glyf table is. |
glyf_len | int = 0 | The length of the glyf table. |
loca | int = 0 | Where the loca table is. |
loca_len | int = 0 | The length of the loca table. |
hmtx | int = 0 | Where the hmtx table is. |
kern | int = 0 | Where the kern table is. |
cmap_sub | int = 0 | Where the cmap subtable is. |
cmap_symbol | bool = false | The cmap is a symbol one. |
num_hmetrics | int = 0 | The number of horizontal metrics. |
loca_long | bool = false | The loca is the long one. |
ok | bool = false | It was read correctly. |
The example for this item is shown with the ones above: image-Draw.salam
Histogram
struct Histogram| Name | Type | Description |
|---|---|---|
r | void* | The red histogram. |
g | void* | The green histogram. |
b | void* | The blue histogram. |
luma | void* | The brightness histogram. |
import image
func size(name: str, img: image.Image):
println name, "" + img.width + "x" + img.height
end
func main:
mut img := image.NewFilled(8, 4, image.Gray(100))
image.SetPixel(img, 0, 0, image.RGB(255, 0, 0))
size("nearest", image.ResizeNearestNeighbor(img, 4, 2))
size("bilinear", image.ResizeBilinearFilter(img, 16, 8))
size("resize", image.Resize(img, 2, 2, image.ResizeBilinear))
size("near", image.Resize(img, 2, 2, image.ResizeNearest))
size("scale", image.Scale(img, 0.5))
size("crop", image.Crop(img, 2, 1, 3, 2))
clockwise := image.RotateCW(img)
size("clockwise", clockwise)
println image.ToHexRGB(image.GetPixel(clockwise, 3, 0))
size("counterclockwise", image.RotateCCW(img))
println image.ToHexRGB(image.GetPixel(image.Rotate180(img), 7, 3))
println image.ToHexRGB(image.GetPixel(image.FlipHorizontal(img), 7, 0)), image.ToHexRGB(image.GetPixel(image.FlipVertical(img), 0, 3))
size("fit", image.ResizeFit(img, 4, 4))
size("fill", image.ResizeFill(img, 4, 4))
size("thumbnail", image.Thumbnail(img, 2))
mut c := image.NewFilled(2, 1, image.RGB(200, 100, 50))
image.Grayscale(c)
println image.ToHexRGB(image.GetPixel(c, 0, 0))
image.Invert(c)
image.Brightness(c, 10)
image.Contrast(c, 1.5)
println image.ToHexRGB(image.GetPixel(c, 0, 0))
image.Threshold(c, 128)
println image.ToHexRGB(image.GetPixel(c, 0, 0))
mut dot := image.NewFilled(5, 5, image.Gray(0))
image.SetPixel(dot, 2, 2, image.Gray(255))
blurred := image.Blurred(dot, 1)
println image.GetPixel(blurred, 2, 2).r < 255, image.GetPixel(blurred, 1, 2).r > 0
println image.GetPixel(image.Sharpened(dot, 1.0), 2, 2).r
mut base := image.NewFilled(2, 2, image.Gray(0))
image.Overlay(base, image.NewFilled(1, 1, image.Gray(200)), 1, 1, 0.5)
println image.ToHexRGB(image.GetPixel(base, 1, 1)), image.ToHexRGB(image.GetPixel(base, 0, 0))
mut hist := image.ComputeHistogram(dot)
println image.HistogramGet(hist.luma, 0), image.HistogramGet(hist.luma, 255), image.HistogramGet(hist.r, 255), image.HistogramGet(hist.g, 0), image.HistogramGet(hist.b, 0)
image.HistogramFree(hist)
black := image.NewFilled(5, 5, image.Gray(0))
diff := image.Diff(dot, black)
println image.GetPixel(diff, 2, 2).r, image.GetPixel(diff, 0, 0).r
println (image.MeanAbsError(dot, black) * 100.0 + 0.5) as i64, (image.PSNR(dot, black) + 0.5) as i64
endTextStyle
struct TextStyle| Name | Type | Description |
|---|---|---|
size | f64 = 16 | The size in pixels. |
rotate | f64 = 0 | The rotation in degrees. |
skew | f64 = 0 | The skew. |
tracking | f64 = 0 | The space added between the characters. |
kern | bool = true | Adjust the spacing of pairs. |
dir | int = 0 | The direction, one of the TextDir... constants. |
shape | bool = true | Join the Persian and Arabic letters into their connected shapes. |
import image
import io
func main:
println image.FindSystemFont(), image.FindArabicFont()
mut ok := false
mut font := image.LoadSystemFont(ok)
if not ok:
font = image.LoadFont("Vazirmatn-Regular.ttf", ok)
end
if not ok:
println "no font was found"
ret
end
println image.FontValid(font), image.UnitsPerEm(font), image.NumGlyphs(font)
size := 32.0
println image.ScaleFactor(font, size), image.AscentPixels(font, size), image.DescentPixels(font, size), image.LineHeightPixels(font, size)
a := image.GlyphIndex(font, 65)
v := image.GlyphIndex(font, 86)
println image.GlyphAdvance(font, a), image.KernAdvance(font, a, v), image.GlyphHasOutline(font, a)
mut x0 := 0
mut y0 := 0
mut x1 := 0
mut y1 := 0
println image.GlyphBox(font, a, x0, y0, x1, y1), x1 - x0, y1 - y0
mut img := image.NewFilled(400, 120, image.Gray(255))
black := image.Gray(0)
_ := image.DrawTextTTF(img, 10.0, 40.0, "Salam", black, font, size)
println image.TextWidthTTF(font, "Salam", size)
style := image.TextStyle { size = 28.0, tracking = 1.0, kern = true, dir = image.TextDirAuto, shape = true }
_ := image.DrawTextStyled(img, 10.0, 80.0, "سلام دنیا", black, font, style)
println image.TextWidthStyled(font, "سلام دنیا", style), image.TextInkWidth(font, "سلام", style), image.TextInkHeight(font, "سلام", style)
mut width := 0.0
mut height := 0.0
println image.TextInkSize(font, "سلام", style, width, height), width, height
mut a0 := 0.0
mut b0 := 0.0
mut a1 := 0.0
mut b1 := 0.0
println image.TextBounds(font, "سلام", style, a0, b0, a1, b1)
println image.FitSizeToWidth(font, "سلام", style, 200.0, 96.0), image.FitSizeToBox(font, "سلام", style, 200.0, 50.0, 96.0)
_ := image.DrawGlyphStyled(img, a, 300.0, 40.0, black, font, style)
_ := image.DrawCodepointStyled(img, 1600, 340.0, 40.0, black, font, style)
_ := image.DrawTextCentered(img, 200.0, 60.0, "middle", black, font, style)
_ := image.DrawTextCenteredIn(img, "middle", black, font, style)
_ := image.DrawTextInBox(img, 0.0, 0.0, 200.0, 60.0, "box", black, font, style, image.TextAlignRight, image.TextVAlignMiddle)
_ := image.DrawTextFitBox(img, 0.0, 60.0, 200.0, 60.0, "fit", black, font, style, 0.8, 64.0)
_ := image.DrawTextFitImage(img, "سلام", black, font, style, 0.9, 120.0)
println image.TextAlignLeft, image.TextAlignCenter, image.TextVAlignTop, image.TextVAlignBottom, image.TextVAlignBaseline
_ := image.Save(img, "salam-text-en.png")
data := io.ReadFile("Vazirmatn-Regular.ttf")
mut f2 := image.ParseFont(data as void*, data.len(), ok)
mut f3 := image.ParseFontIndex(data as void*, data.len(), 0, ok)
mut f4 := image.LoadFontIndex("NotoSansCJK.ttc", 0, ok)
println image.IsCFFFont(data as void*, data.len())
image.FreeFont(f2)
image.FreeFont(f3)
image.FreeFont(f4)
image.FreeFont(font)
image.Free(img)
endConstants and variables
ResizeNearest
const ResizeNearest: i32 = 0The example for this item is shown with the ones above: image-Edit.salam
ResizeBilinear
const ResizeBilinear: i32 = 1The example for this item is shown with the ones above: image-Edit.salam
TextAlignLeft
const TextAlignLeft: i32 = 0The example for this item is shown with the ones above: image-Font.salam
TextAlignCenter
const TextAlignCenter: i32 = 1The example for this item is shown with the ones above: image-Font.salam
TextAlignRight
const TextAlignRight: i32 = 2The example for this item is shown with the ones above: image-Font.salam
TextVAlignTop
const TextVAlignTop: i32 = 0The example for this item is shown with the ones above: image-Font.salam
TextVAlignMiddle
const TextVAlignMiddle: i32 = 1The example for this item is shown with the ones above: image-Font.salam
TextVAlignBottom
const TextVAlignBottom: i32 = 2The example for this item is shown with the ones above: image-Font.salam
TextVAlignBaseline
const TextVAlignBaseline: i32 = 3The example for this item is shown with the ones above: image-Font.salam
TextDirAuto
const TextDirAuto: i32 = 0import image
func main:
println image.IsRTLText("سلام"), image.IsRTLText("hello")
println image.BaseDirection("سلام hello") == image.TextDirRTL, image.BaseDirection("hello سلام") == image.TextDirLTR
println image.TextDirAuto
visual := image.ToVisualOrder("abc", image.TextDirLTR)
println visual
shaped := image.ShapeArabic("سلام")
println shaped.len() > 0, shaped != "سلام"
println image.ToVisualOrder("سلام", image.TextDirRTL) != "سلام"
endTextDirLTR
const TextDirLTR: i32 = 1The example for this item is shown with the ones above: image-Bidi.salam
TextDirRTL
const TextDirRTL: i32 = 2The example for this item is shown with the ones above: image-Bidi.salam
FormatUnknown
const FormatUnknown: i32 = 0The example for this item is shown with the ones above: image-Draw.salam
FormatPNG
const FormatPNG: i32 = 1The example for this item is shown with the ones above: image-Draw.salam
FormatBMP
const FormatBMP: i32 = 2The example for this item is shown with the ones above: image-Draw.salam
FormatJPEG
const FormatJPEG: i32 = 3The example for this item is shown with the ones above: image-Draw.salam
FormatWebP
const FormatWebP: i32 = 4The example for this item is shown with the ones above: image-Draw.salam
FormatGIF
const FormatGIF: i32 = 5The example for this item is shown with the ones above: image-Draw.salam
FontWidth
const FontWidth: i32 = 5The example for this item is shown with the ones above: image-Draw.salam
FontHeight
const FontHeight: i32 = 7The example for this item is shown with the ones above: image-Draw.salam
Functions
IsWebP
func IsWebP(p: void*, n: int): boolThe example for this item is shown with the ones above: image-Draw.salam
SaveWebP
func SaveWebP(img: Image, path: str): boolThe example for this item is shown with the ones above: image-Draw.salam
OpenWebP
func OpenWebP(path: str, ok &: bool): ImageThe example for this item is shown with the ones above: image-Draw.salam
EncodePNG
func EncodePNG(img: Image): compress.ByteBufThe example for this item is shown with the ones above: image-Draw.salam
SavePNG
func SavePNG(img: Image, path: str): boolThe example for this item is shown with the ones above: image-Draw.salam
DecodePNG
func DecodePNG(p: void*, n: int, ok &: bool): ImageThe example for this item is shown with the ones above: image-Draw.salam
OpenPNG
func OpenPNG(path: str, ok &: bool): ImageThe example for this item is shown with the ones above: image-Draw.salam
TextBounds
func TextBounds(f: Font, text: str, st: TextStyle, x0 &: f64, y0 &: f64, x1 &: f64, y1 &: f64): boolThe example for this item is shown with the ones above: image-Font.salam
TextInkWidth
func TextInkWidth(f: Font, text: str, st: TextStyle): f64The example for this item is shown with the ones above: image-Font.salam
TextInkHeight
func TextInkHeight(f: Font, text: str, st: TextStyle): f64The example for this item is shown with the ones above: image-Font.salam
TextInkSize
func TextInkSize(f: Font, text: str, st: TextStyle, w &: f64, h &: f64): boolThe example for this item is shown with the ones above: image-Font.salam
FitSizeToWidth
func FitSizeToWidth(f: Font, text: str, st: TextStyle, target_w: f64, max_size: f64): f64The example for this item is shown with the ones above: image-Font.salam
FitSizeToBox
func FitSizeToBox(f: Font, text: str, st: TextStyle, target_w: f64, target_h: f64, max_size: f64): f64The example for this item is shown with the ones above: image-Font.salam
RGB
func RGB(r: int, g: int, b: int): ColorThe example for this item is shown with the ones above: image-Draw.salam
RGBA
func RGBA(r: int, g: int, b: int, a: int): ColorThe example for this item is shown with the ones above: image-Draw.salam
Gray
func Gray(v: int): ColorThe example for this item is shown with the ones above: image-Draw.salam
Equals
func Equals(a: Color, b: Color): boolThe example for this item is shown with the ones above: image-Draw.salam
Luminance
func Luminance(c: Color): intThe example for this item is shown with the ones above: image-Draw.salam
ParseHex
func ParseHex(hex: str): ColorThe example for this item is shown with the ones above: image-Draw.salam
ToHex
func ToHex(c: Color): str#336699ff.The example for this item is shown with the ones above: image-Draw.salam
ToHexRGB
func ToHexRGB(c: Color): strThe example for this item is shown with the ones above: image-Draw.salam
Blend
func Blend(dst: Color, src: Color): ColorThe example for this item is shown with the ones above: image-Draw.salam
LerpColor
func LerpColor(a: Color, b: Color, t: f64): ColorThe example for this item is shown with the ones above: image-Draw.salam
EncodeBMP
func EncodeBMP(img: Image): compress.ByteBufThe example for this item is shown with the ones above: image-Draw.salam
SaveBMP
func SaveBMP(img: Image, path: str): boolThe example for this item is shown with the ones above: image-Draw.salam
DecodeBMP
func DecodeBMP(p: void*, n: int, ok &: bool): ImageThe example for this item is shown with the ones above: image-Draw.salam
OpenBMP
func OpenBMP(path: str, ok &: bool): ImageThe example for this item is shown with the ones above: image-Draw.salam
ResizeNearestNeighbor
func ResizeNearestNeighbor(img: Image, new_width: int, new_height: int): ImageThe example for this item is shown with the ones above: image-Edit.salam
ResizeBilinearFilter
func ResizeBilinearFilter(img: Image, new_width: int, new_height: int): ImageThe example for this item is shown with the ones above: image-Edit.salam
Resize
func Resize(img: Image, new_width: int, new_height: int, method: int): ImageThe example for this item is shown with the ones above: image-Edit.salam
Scale
func Scale(img: Image, factor: f64): ImageThe example for this item is shown with the ones above: image-Edit.salam
Crop
func Crop(img: Image, x: int, y: int, w: int, h: int): ImageThe example for this item is shown with the ones above: image-Edit.salam
RotateCW
func RotateCW(img: Image): ImageThe example for this item is shown with the ones above: image-Edit.salam
RotateCCW
func RotateCCW(img: Image): ImageThe example for this item is shown with the ones above: image-Edit.salam
Rotate180
func Rotate180(img: Image): ImageThe example for this item is shown with the ones above: image-Edit.salam
FlipHorizontal
func FlipHorizontal(img: Image): ImageThe example for this item is shown with the ones above: image-Edit.salam
FlipVertical
func FlipVertical(img: Image): ImageThe example for this item is shown with the ones above: image-Edit.salam
ResizeFit
func ResizeFit(img: Image, box_w: int, box_h: int): ImageThe example for this item is shown with the ones above: image-Edit.salam
ResizeFill
func ResizeFill(img: Image, box_w: int, box_h: int): ImageThe example for this item is shown with the ones above: image-Edit.salam
Thumbnail
func Thumbnail(img: Image, max_size: int): ImageThe example for this item is shown with the ones above: image-Edit.salam
DrawLine
func DrawLine(img &: Image, x0: int, y0: int, x1: int, y1: int, c: Color)The example for this item is shown with the ones above: image-Draw.salam
DrawRect
func DrawRect(img &: Image, x: int, y: int, w: int, h: int, c: Color)The example for this item is shown with the ones above: image-Draw.salam
DrawRectFilled
func DrawRectFilled(img &: Image, x: int, y: int, w: int, h: int, c: Color)The example for this item is shown with the ones above: image-Draw.salam
DrawCircle
func DrawCircle(img &: Image, cx: int, cy: int, radius: int, c: Color)The example for this item is shown with the ones above: image-Draw.salam
DrawCircleFilled
func DrawCircleFilled(img &: Image, cx: int, cy: int, radius: int, c: Color)The example for this item is shown with the ones above: image-Draw.salam
Grayscale
func Grayscale(img &: Image)The example for this item is shown with the ones above: image-Edit.salam
Invert
func Invert(img &: Image)The example for this item is shown with the ones above: image-Edit.salam
Brightness
func Brightness(img &: Image, delta: int)The example for this item is shown with the ones above: image-Edit.salam
Contrast
func Contrast(img &: Image, factor: f64)The example for this item is shown with the ones above: image-Edit.salam
Threshold
func Threshold(img &: Image, level: int)The example for this item is shown with the ones above: image-Edit.salam
Blurred
func Blurred(img: Image, radius: int): ImageThe example for this item is shown with the ones above: image-Edit.salam
Sharpened
func Sharpened(img: Image, amount: f64): ImageThe example for this item is shown with the ones above: image-Edit.salam
Overlay
func Overlay(base &: Image, mark: Image, x: int, y: int, opacity: f64)The example for this item is shown with the ones above: image-Edit.salam
ScaleFactor
func ScaleFactor(f: Font, size: f64): f64The example for this item is shown with the ones above: image-Font.salam
AscentPixels
func AscentPixels(f: Font, size: f64): f64The example for this item is shown with the ones above: image-Font.salam
DescentPixels
func DescentPixels(f: Font, size: f64): f64The example for this item is shown with the ones above: image-Font.salam
LineHeightPixels
func LineHeightPixels(f: Font, size: f64): f64The example for this item is shown with the ones above: image-Font.salam
GlyphAdvance
func GlyphAdvance(f: Font, glyph: int): intThe example for this item is shown with the ones above: image-Font.salam
KernAdvance
func KernAdvance(f: Font, glyph1: int, glyph2: int): intThe example for this item is shown with the ones above: image-Font.salam
DecodeWebP
func DecodeWebP(p: void*, n: int, ok &: bool): ImageThe example for this item is shown with the ones above: image-Draw.salam
EncodeWebP
func EncodeWebP(img: Image): compress.ByteBufThe example for this item is shown with the ones above: image-Draw.salam
EncodeWebPQuality
func EncodeWebPQuality(img: Image, quality: int): compress.ByteBufThe example for this item is shown with the ones above: image-Draw.salam
DrawTextCentered
func DrawTextCentered(img &: Image, cx: f64, cy: f64, text: str, col: Color, f: Font, st: TextStyle): f64The example for this item is shown with the ones above: image-Font.salam
DrawTextCenteredIn
func DrawTextCenteredIn(img &: Image, text: str, col: Color, f: Font, st: TextStyle): f64The example for this item is shown with the ones above: image-Font.salam
DrawTextInBox
func DrawTextInBox(img &: Image, x: f64, y: f64, w: f64, h: f64, text: str, col: Color, f: Font, st: TextStyle, halign: int, valign: int): f64The example for this item is shown with the ones above: image-Font.salam
DrawTextFitBox
func DrawTextFitBox(img &: Image, x: f64, y: f64, w: f64, h: f64, text: str, col: Color, f: Font, st: TextStyle, fill: f64, max_size: f64): f64The example for this item is shown with the ones above: image-Font.salam
DrawTextFitImage
func DrawTextFitImage(img &: Image, text: str, col: Color, f: Font, st: TextStyle, fill: f64, max_size: f64): f64The example for this item is shown with the ones above: image-Font.salam
IsGIF
func IsGIF(p: void*, n: int): boolThe example for this item is shown with the ones above: image-Draw.salam
DecodeGIF
func DecodeGIF(p: void*, n: int, ok &: bool): ImageThe example for this item is shown with the ones above: image-Draw.salam
OpenGIF
func OpenGIF(path: str, ok &: bool): ImageThe example for this item is shown with the ones above: image-Draw.salam
EncodeGIF
func EncodeGIF(img: Image): compress.ByteBufThe example for this item is shown with the ones above: image-Draw.salam
SaveGIF
func SaveGIF(img: Image, path: str): boolThe example for this item is shown with the ones above: image-Draw.salam
New
func New(width: int, height: int): ImageThe example for this item is shown with the ones above: image-Draw.salam
NewFilled
func NewFilled(width: int, height: int, c: Color): ImageThe example for this item is shown with the ones above: image-Draw.salam
Free
func Free(img &: Image)The example for this item is shown with the ones above: image-Draw.salam
Clone
func Clone(img: Image): ImageThe example for this item is shown with the ones above: image-Draw.salam
IsEmpty
func IsEmpty(img: Image): boolThe example for this item is shown with the ones above: image-Draw.salam
InBounds
func InBounds(img: Image, x: int, y: int): boolThe example for this item is shown with the ones above: image-Draw.salam
GetPixel
func GetPixel(img: Image, x: int, y: int): ColorThe example for this item is shown with the ones above: image-Draw.salam
SetPixel
func SetPixel(img &: Image, x: int, y: int, c: Color)The example for this item is shown with the ones above: image-Draw.salam
BlendPixel
func BlendPixel(img &: Image, x: int, y: int, c: Color)The example for this item is shown with the ones above: image-Draw.salam
Fill
func Fill(img &: Image, c: Color)The example for this item is shown with the ones above: image-Draw.salam
FillHex
func FillHex(img &: Image, hex: str)#202040.The example for this item is shown with the ones above: image-Draw.salam
ParseFontIndex
func ParseFontIndex(p: void*, n: int, index: int, ok &: bool): FontThe example for this item is shown with the ones above: image-Font.salam
ParseFont
func ParseFont(p: void*, n: int, ok &: bool): FontThe example for this item is shown with the ones above: image-Font.salam
LoadFont
func LoadFont(path: str, ok &: bool): Font.ttf or .otf file.The example for this item is shown with the ones above: image-Font.salam
LoadFontIndex
func LoadFontIndex(path: str, index: int, ok &: bool): FontThe example for this item is shown with the ones above: image-Font.salam
FreeFont
func FreeFont(f &: Font)The example for this item is shown with the ones above: image-Font.salam
FontValid
func FontValid(f: Font): boolThe example for this item is shown with the ones above: image-Font.salam
IsCFFFont
func IsCFFFont(p: void*, n: int): boolThe example for this item is shown with the ones above: image-Font.salam
UnitsPerEm
func UnitsPerEm(f: Font): intThe example for this item is shown with the ones above: image-Font.salam
NumGlyphs
func NumGlyphs(f: Font): intThe example for this item is shown with the ones above: image-Font.salam
EncodeJPEG
func EncodeJPEG(img: Image, quality: int): compress.ByteBufThe example for this item is shown with the ones above: image-Draw.salam
SaveJPEG
func SaveJPEG(img: Image, path: str, quality: int): boolThe example for this item is shown with the ones above: image-Draw.salam
DecodeJPEG
func DecodeJPEG(p: void*, n: int, ok &: bool): ImageThe example for this item is shown with the ones above: image-Draw.salam
OpenJPEG
func OpenJPEG(path: str, ok &: bool): ImageThe example for this item is shown with the ones above: image-Draw.salam
GlyphIndex
func GlyphIndex(f: Font, codepoint: int): intThe example for this item is shown with the ones above: image-Font.salam
ComputeHistogram
func ComputeHistogram(img: Image): HistogramThe example for this item is shown with the ones above: image-Edit.salam
HistogramGet
func HistogramGet(channel: void*, bucket: int): intThe example for this item is shown with the ones above: image-Edit.salam
HistogramFree
func HistogramFree(h &: Histogram)The example for this item is shown with the ones above: image-Edit.salam
Diff
func Diff(a: Image, b: Image): ImageThe example for this item is shown with the ones above: image-Edit.salam
MeanAbsError
func MeanAbsError(a: Image, b: Image): f64The example for this item is shown with the ones above: image-Edit.salam
PSNR
func PSNR(a: Image, b: Image): f64The example for this item is shown with the ones above: image-Edit.salam
DrawGlyphStyled
func DrawGlyphStyled(img &: Image, glyph: int, x: f64, y: f64, col: Color, f: Font, st: TextStyle)The example for this item is shown with the ones above: image-Font.salam
DrawCodepointStyled
func DrawCodepointStyled(img &: Image, codepoint: int, x: f64, y: f64, col: Color, f: Font, st: TextStyle): f64The example for this item is shown with the ones above: image-Font.salam
DrawTextStyled
func DrawTextStyled(img &: Image, x: f64, y: f64, text: str, col: Color, f: Font, st: TextStyle): f64The example for this item is shown with the ones above: image-Font.salam
DrawTextTTF
func DrawTextTTF(img &: Image, x: f64, y: f64, text: str, col: Color, f: Font, size: f64): f64The example for this item is shown with the ones above: image-Font.salam
TextWidthStyled
func TextWidthStyled(f: Font, text: str, st: TextStyle): f64The example for this item is shown with the ones above: image-Font.salam
TextWidthTTF
func TextWidthTTF(f: Font, text: str, size: f64): f64The example for this item is shown with the ones above: image-Font.salam
FindSystemFont
func FindSystemFont(): strThe example for this item is shown with the ones above: image-Font.salam
FindArabicFont
func FindArabicFont(): strThe example for this item is shown with the ones above: image-Font.salam
LoadSystemFont
func LoadSystemFont(ok &: bool): FontThe example for this item is shown with the ones above: image-Font.salam
ShapeArabic
func ShapeArabic(text: str): strThe example for this item is shown with the ones above: image-Bidi.salam
IsRTLText
func IsRTLText(text: str): boolThe example for this item is shown with the ones above: image-Bidi.salam
BaseDirection
func BaseDirection(text: str): intThe example for this item is shown with the ones above: image-Bidi.salam
ToVisualOrder
func ToVisualOrder(text: str, dir: int): strThe example for this item is shown with the ones above: image-Bidi.salam
DetectFormat
func DetectFormat(p: void*, n: int): intThe example for this item is shown with the ones above: image-Draw.salam
FormatFromExt
func FormatFromExt(path: str): intThe example for this item is shown with the ones above: image-Draw.salam
Decode
func Decode(p: void*, n: int, ok &: bool): ImageThe example for this item is shown with the ones above: image-Draw.salam
Open
func Open(path: str, ok &: bool): ImageThe example for this item is shown with the ones above: image-Draw.salam
FlattenAlpha
func FlattenAlpha(img: Image, bg: Color): ImageThe example for this item is shown with the ones above: image-Draw.salam
Convert
func Convert(img: Image, format: int): ImageThe example for this item is shown with the ones above: image-Draw.salam
Encode
func Encode(img: Image, format: int, quality: int): compress.ByteBufThe example for this item is shown with the ones above: image-Draw.salam
SaveQuality
func SaveQuality(img: Image, path: str, quality: int): boolThe example for this item is shown with the ones above: image-Draw.salam
Save
func Save(img: Image, path: str): boolThe example for this item is shown with the ones above: image-Draw.salam
GlyphBox
func GlyphBox(f: Font, glyph: int, x0 &: int, y0 &: int, x1 &: int, y1 &: int): boolThe example for this item is shown with the ones above: image-Font.salam
GlyphHasOutline
func GlyphHasOutline(f: Font, glyph: int): boolThe example for this item is shown with the ones above: image-Font.salam
DrawText
func DrawText(img &: Image, x: int, y: int, text: str, c: Color, scale: int)The example for this item is shown with the ones above: image-Draw.salam
TextWidth
func TextWidth(text: str, scale: int): intThe example for this item is shown with the ones above: image-Draw.salam