Img add

From Sim Innovations Wiki
Jump to navigation Jump to search

Description

image_id = img_add(filename, x, y, width, height)
image_id = img_add(filename, x, y, width, height, style)

img_add is used to show an image on the specified location. The image is also stored in memory for further references.

Return value

Argument Type Description
image_id ID This value can be used for further reference. Functions such as move and img_rotate can use this image_id. Its good practice to store this image_id in your logic code.

Arguments

# Argument Type Description
1 filename String This is the filename of the image you would like to show. Note that this is both filename and extension. Its good practice to always the PNG format for images. JPG and BMP are also supported, but not recommended.
2 x Number This is the most left point of the canvas where your image should be shown.
3 y Number This is the most top point of the canvas where your image should be shown.
4 width Number The image width on the canvas. Note that the software won't preserve the aspect ratio. Scaling will be done, both stretching and cropping of the image. From AM 2.1.1, nil will make the image the same width as the PNG image.
5 height Number The image height on the canvas. Note that the software won't preserve the aspect ratio. Scaling will be done, both stretching and cropping of the image. From AM 2.1.1, nil will make the image the same height as the PNG image.
6 style String (Optional) The style to use. See the paragraph below for available style arguments.

Style

Argument Type Description
scale_mode String Describe how the image should be scaled inside the box. Can be "stretch", "aspect_fit" or "aspect_fill". Defaults to "stretch".
halign String The horizontal alignment of the image within the image box. Can be "left", "center" or "right".
valign String The vertical alignment of the image within the image box. Can be "top", "center" or "bottom".
visible Boolean Should the image be visible. Available from AM/AP 3.5.
background_color String Show a background color. Available from AM/AP 3.6.

Example

-- Load and display text and images
myimage1 = img_add("myimage1.png", 0, 0, 200, 200)
myimage2 = img_add("myimage2.png", 200, 0, 200, 200)

-- Rotate image1
rotate(myimage1, 90)