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.

Methods

compressJPEG

(
  • quality
)

Compresses image data to JPEG.

Can be used to compress data and save some space.

Parameters:

  • quality Number

    JPEG compression quality level by default 0.7 is used (1.0 means max quality).

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

    CSS Color string.

fileIsImage

(
  • file
)
Boolean static

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

Parameters:

  • file File

    File to check format of.

Returns:

Boolean:

True if the file refers to a supported image format.

getImageData

(
  • onLoad
)
ImageData

Read the image data and return the raw pixel data of the image as a ImageData object.

Parameters:

  • onLoad Function

    Callback method to retrieve the image data, receives (data, width, height) as parameters.

Returns:

ImageData:

Image data object with the content of the image object.

getImageSize

(
  • onLoad
)

Get the image size if its available, if the image size its not available it has to be loaded first.

Parameters:

  • onLoad Function

    Callack method to get the image size, receives (width, height) as parameters.

hasTransparency

(
  • perPixel
)
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.

Parameters:

  • perPixel Boolean

    Check every individual pixel to see if the image actually has tranparency data, default is false.

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).

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

Attributes

height

Number

Image height (in pixels), if not available should be set -1.

Stores the real size of the image not the used to represent it, its obtained from the naturalHeight attribute of the image element.

width

Number

Image width (in pixels), if not available should be set -1.

Stores the real size of the image not the used to represent it, its obtained from the naturalWidth attribute of the image element.