# Two.Image
Extends: Two.Rectangle
A convenient package to display images scaled to fit specific dimensions. Unlike Two.Sprite, this class scales the image to the provided width and height rather than using the image's native dimensions. By default, images are scaled to 'fill' within the bounds while preserving aspect ratio.
# Constructor
| Argument | Description |
|---|---|
| src | The URL path or Two.Texture to be used as the bitmap data displayed on the image. |
| ox | The initial x position of the Two.Image. |
| oy | The initial y position of the Two.Image. |
| width | The width to display the image at. |
| height | The height to display the image at. |
| mode | The fill mode |
# Modes
Two.Image.Modes
Different mode types to render an image inspired by Figma.
Modes.fill: Scale image to fill the bounds while preserving aspect ratio.
Modes.fit: Scale image to fit within bounds while preserving aspect ratio.
Modes.crop: Scale image to fill bounds while preserving aspect ratio, cropping excess.
Modes.tile: Repeat image at original size to fill the bounds.
Modes.stretch: Stretch image to fill dimensions, ignoring aspect ratio.
# fromObject
Two.Image.fromObject
Returns: Two.Image
| Argument | Description |
|---|---|
| obj | Object notation of a Two.Image to create a new instance |
# copy
Two.Image.copy
| Argument | Description |
|---|---|
| image | The reference Two.Image |
Copy the properties of one Two.Image onto another.
# clone
Two.Image.clone
Returns: Two.Image
| Argument | Description |
|---|---|
| parent | The parent group or scene to add the clone to. |
Create a new instance of Two.Image with the same properties of the current image.
# toObject
Two.Image.toObject
Returns: Object
Return a JSON compatible plain object that represents the image.
# dispose
Two.Image.dispose
Returns: Two.Image
Release the image's renderer resources and detach all events. This method disposes the texture (calling dispose() for thorough cleanup) and inherits comprehensive cleanup from the Rectangle/Path hierarchy while preserving the renderer type for potential re-attachment.