Image Class

Extends Resource
Module: Resources

Image class is used to store image data that is used to create Textures.

Images can be stored in mutiple formats.

Some formats (tga, tiff, etc) are converted to png or jpeg in order to work with the rest of the code.

Constructor

Image

(
  • data
  • encoding
)

Parameters:

  • data ArrayBuffer, Base64, String

    Can be URL to image, ArrayBuffer data or base64 encoded data.

  • encoding String

    Image encoding, required for ArrayBuffer data.

Methods

createSolidColor

(
  • color
)

Create a new image with 1x1 resolution with solid color.

Can be called externally on data load error to load dummy data.

Parameters:

  • color String

    Color code

encodeData

()

Compresses image data to JPEG or PNG and stores in base64 encoding.

If the image has transparency it is stored as PNG otherwise the image is stored in JPEG with 1.0 quality.

Can be used to compress data and save space.

fileIsImage

(
  • file
)
Boolean static

Check if a file name refers to a supported binary image file.

Parameters:

  • file File

Returns:

Boolean:

True if the file refers to a supported image format.

hasTransparency

() Boolean

Check if this image has alpha channel.

This checks the file encoding if the file a GIF or a PNG is assumed that the file has alpha channel.

Returns:

Boolean:

True if the image is encoded as PNG or GIF

loadArrayBufferData

(
  • data
  • encoding
)

Load arraybuffer data to this image.

Creates a blob with data to be stored on data atribute and used by external objects.

Parameters:

  • data ArrayBuffer

    Data to be loaded.

  • encoding String

    Image enconding (jpeg, png, etc).

loadTGAData

(
  • data
)

Load .tga file from ArrayBuffer data.

After loading data is converted to JPEG format and stored in base64 encoding.

Parameters:

  • data ArrayBuffer

    Data to be loaded.

toJSON

(
  • meta
)
Object

Serialize Image resource to json.

If image is stored as URL it is converter to PNG or JPEG.

Parameters:

  • meta Object

Returns:

Object:

json