Code Examples

This section of the documentation is targeted towards programmers with PHP experience. It will help you understand how the avatarMaker backend works and how you can integrate it into an existing application.

Only publicly available methods are described here, as the others can't be used outside the class scope.

Note

The avatarMaker is in continuous development based on user's feedback and necessities. For this reason, all the methods and functions discussed here may change in future releases.

outAppConfig()

Description

This function will generate or load the configuration file and all the preview images. The generated data will be saved into the cache folder and it will be served from the disk for all the subsequent calls.

After calling this function, it will set the appropriate headers for JSON data, send the configuration and close the connection.

Parameters

No Parameters

Return

No Return

Code Example

public function outAppConfig( ) { ... }

setAvatar()

Description

This function loads an avatar tree into the class memory. The JSON data can be passed through a paramether or, if this is empty, the function will try to load it from php://input.

Parameters

Parameter Type Description
$json string optional A JSON encoded avatar tree

Return

true in case of success, false otherwise.

Code Example

public function setAvatar( $json = false ) { ... }

setAvatarMd5()

Description

This function will generate an avatar tree based on the given MD5 string.

Warning

For a given hash, this will generate always with the same avatar, but if the content of the assets folder is changed, the generated avatar for the same hash will change!

Parameters

Parameter Type Description
$md5 string required A valid MD5 string

Return

true in case of success, false otherwise.

Code Example

public function setAvatarMd5( $md5 ) { ... }

setAvatarGET()

Description

Generates an avatar tree based on GET data. If the supplied data is only partial it will generate an incomplete avatar tree (It can still be rendered).

Parameters

No Parameters

Return

No Return

Code Example

public function setAvatarGET( ){ ... }

renderAvatar()

Description

Parameters

Parameter Type Description
$savePath string optional A writable path (relative or absolute) with file name and extension (ex. /test/image.png)

Note

savePath will be ignored if the renderer_format key in the configuration is not set to one of the _saved options. If it is, this parameter is required for saving the avatar.

Code Example

public function renderAvatar( $savePath = false ) { ... }