crop_image - Crop image to specific dimensions
nil
crop_image( width, height )
For some cases, primarily resizing text, the default scale- and resize- function
behavior is unappealing because any under or oversampling will rapidly
decrease quality. This function act as a resize down to 1:1 scale for values
larger than the initial size, and changes effective texture coordinates for
values larger than the initial size. This will have the side effect of
reverting other texture sampling manipulations like mirroring, and it will
reset any pending resize transformation chains.
- 1
- Another option to obtain the same effect is to create a null_surface, link
the image to this surface and enable shallow clipping but it results in a
more complex structure to render and more code to properly set up.
function crop_image0()
local img = load_image("test.png");
local props = image_surface_properties(img);
crop_image(img, 0.5 * props.width, 0.5 * props.height);
show_image(img);
end
function crop_image1()
local img = render_text([[onts/default.ttf,18 local props = image_surface_properties(img);
crop_image(img, 0.5 * props.width, 0.5 * props.height);
show_image(img);
end