Font
#struct FontA TrueType or OpenType font.
| Name | Type | Description |
|---|---|---|
Font | typeset.Font | The gui.typeset font this image font wraps; every field of it can also be read directly. |
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)
end8 6 false true false #ff0000ff #8f8f9fff #202040 #00ff00 #c8c8c8 51 102 153 255 92 true #336699ff #646464 30 5 7 true true true true true true true 8 true true 8 6 8 true true true true false true 8 6 true true 8 8 true true 4 #ffffffff 8 true 8 true true 8 6 true true true 8 6 true true true 6