image_new
result = image_new(width, height, [r=0, g=0, b=0])
Input: width, height, r · Output: result
What it is
Creates a blank solid-color canvas. width and height are positive integers giving the canvas size in pixels. r, g, b are optional named numbers 0–255 giving the fill color's channel values (default 0, i.e. solid black).
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = image_new(width, height, [r=0, g=0, b=0]) | width —width and height are positive integers giving the canvas size in pixels.height —width and height are positive integers giving the canvas size in pixels.r number, optional (default 0, g=0, b=0)r, g, b are optional named numbers 0–255 giving the fill color's channel values (default 0, i.e. | result Image | Returns a new Image of exactly width x height pixels. The only way to build a synthetic image with no file on disk. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
img = image_new(10, 10, r=0, g=0, b=0)
big = resize(img, 20, 15, method="bilinear")
print(big.width, big.height) # 20 15
20 15
from images
img = image_new(20, 20, r=0, g=0, b=0)
shifted = imtranslate(img, 5, 3, fill=255)
scaled = imscale(img, 1.5, fill=0)
imshow(shifted)
M = affine_scale(2, 1.5) * affine_shear(0.2, 0) * affine_identity()
print(shifted.width, scaled.width, M)
20 30 [2, 0.4, 0; 0, 1.5, 0; 0, 0, 1]
from images
canvas = image_new(40, 30, r=200, g=200, b=200)
m = [10, 40, 250; 90, 140, 190; 220, 255, 30]
gray = image_from_matrix(m)
save_image("/tmp/gray.bmp", gray)
imagesc(m, colormap="viridis") # false-color view of the same matrix
big = resize(canvas, 80, 60, method="bilinear")
piece = crop(big, 10, 10, 30, 20)
print(piece.width, piece.height)
imshow(piece)
from images
How it works
image_new(width, height, [r=0, g=0, b=0]) — a blank solid- color canvas; the constructor load_image's round trip otherwise has no Qu-level counterpart for (there's no Image literal syntax, matching zeros/ones filling the same gap for matrices). Lets a script build and test a synthetic image entirely in Qu, with no external file needed.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.