{"_id":"570eb3e1a38d470e0060c9b1","__v":4,"category":{"_id":"570a5676ade45d0e00c1ad33","__v":0,"project":"56abbf55f25f160d00e17f4e","version":"56abbf55f25f160d00e17f51","sync":{"url":"","isSync":false},"reference":true,"createdAt":"2016-04-10T13:34:46.864Z","from_sync":false,"order":3,"slug":"client-side-api","title":"Client Side API"},"parentDoc":null,"user":"56abbec30b9e0b0d00616274","version":{"_id":"56abbf55f25f160d00e17f51","project":"56abbf55f25f160d00e17f4e","__v":12,"createdAt":"2016-01-29T19:36:53.665Z","releaseDate":"2016-01-29T19:36:53.665Z","categories":["56abbf56f25f160d00e17f52","56abca6bf9757e0d007c6650","56acddfa0ab3c00d00ce3332","56af65da9d32e30d0006d30f","56af66cab34d210d003d9ad0","56af6afcd21e9c0d00b628d1","56af6d6ecc4cbd0d00ce2c88","5705b12221cfed0e00e8c580","570a5676ade45d0e00c1ad33","570d7d25d1e4b82000d9e385","570eac3c3160d10e0041df0e","575709000fd6a3200010dded"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"project":"56abbf55f25f160d00e17f4e","updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-04-13T21:02:25.125Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":true,"order":5,"body":"## Exporting a custom avatar\n\nKongregate's Avatar Export API gives you the ability to export in-game avatars and let users use them as their Kongregate profile avatar. When you call the `submitAvatar` function, the user will receive a notification that the game is requesting to change their avatar. At that point, they'll be able to crop the suggested image if they wish, and can choose to accept or decline the avatar modification. This functionality can be used to provide bonuses for players, as well as more directly with avatar creator/editor apps, and probably other uses we haven't even thought of yet.\n\nYou can use the `submitAvatar` function on the `images` property of the Kongregate API object to export a `DisplayObject` or a Base64-encoded string containing the image data to be converted to a user avatar. It is highly recommended that avatars be at least 40x40px:\n[block:parameters]\n{\n \"data\": {\n \"h-0\": \"Name\",\n \"h-1\": \"Type\",\n \"h-2\": \"Description\",\n \"0-0\": \"`display_object`\",\n \"0-1\": \"DisplayObject or Base64-encoded string\",\n \"0-2\": \"The DisplayObject or Base64-encoded string containing the avatar image\",\n \"1-0\": \"`callback`\",\n \"1-1\": \"Function\",\n \"1-2\": \"The callback function to be called when the operation is complete.\"\n },\n \"cols\": 3,\n \"rows\": 2\n}\n[/block]\nThe callback function is passed a single boolean parameter which will be true if the user has accepted the avatar and false if they decide not to use it.\n\n**Example: Exporting a rectangle**\n[block:code]\n{\n \"codes\": [\n {\n \"code\": \"var rect:Shape = new Shape();\\nrect.graphics.lineStyle(1);\\nrect.graphics.beginFill(0x0000FF, 1);\\nrect.graphics.drawRect(0, 0, 75, 50);\\n\\nkongregate.images.submitAvatar(rect, onAvatarComplete);\\n\\nfunction onAvatarComplete(success:Boolean) {\\n if(success) {\\n trace(\\\"That user must love rectangles!\\\")\\n } else {\\n trace(\\\"Next time I'll try a triangle :(\\\")\\n }\\n}\",\n \"language\": \"javascript\",\n \"name\": \"ActionScript 3\"\n },\n {\n \"code\": \"var base64PNG = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVQYV2NgYAAAAAMAAWgmWQ0AAAAASUVORK5CYII=';\\n\\nkongregate.images.submitAvatar(base64PNG, function(success) {\\n\\tif (success) {\\n \\tconsole.log('That is a small avatar');\\n }\\n});\",\n \"language\": \"javascript\"\n }\n ]\n}\n[/block]","excerpt":"Ask the user to change their avatar\n`submitAvatar(display_object, callback)`","slug":"client-api-images-submitavatar","type":"fn","title":"Images.SubmitAvatar"}

Images.SubmitAvatar

Ask the user to change their avatar
`submitAvatar(display_object, callback)`

## Exporting a custom avatar
Kongregate's Avatar Export API gives you the ability to export in-game avatars and let users use them as their Kongregate profile avatar. When you call the `submitAvatar` function, the user will receive a notification that the game is requesting to change their avatar. At that point, they'll be able to crop the suggested image if they wish, and can choose to accept or decline the avatar modification. This functionality can be used to provide bonuses for players, as well as more directly with avatar creator/editor apps, and probably other uses we haven't even thought of yet.
You can use the `submitAvatar` function on the `images` property of the Kongregate API object to export a `DisplayObject` or a Base64-encoded string containing the image data to be converted to a user avatar. It is highly recommended that avatars be at least 40x40px:
[block:parameters]
{
"data": {
"h-0": "Name",
"h-1": "Type",
"h-2": "Description",
"0-0": "`display_object`",
"0-1": "DisplayObject or Base64-encoded string",
"0-2": "The DisplayObject or Base64-encoded string containing the avatar image",
"1-0": "`callback`",
"1-1": "Function",
"1-2": "The callback function to be called when the operation is complete."
},
"cols": 3,
"rows": 2
}
[/block]
The callback function is passed a single boolean parameter which will be true if the user has accepted the avatar and false if they decide not to use it.
**Example: Exporting a rectangle**
[block:code]
{
"codes": [
{
"code": "var rect:Shape = new Shape();\nrect.graphics.lineStyle(1);\nrect.graphics.beginFill(0x0000FF, 1);\nrect.graphics.drawRect(0, 0, 75, 50);\n\nkongregate.images.submitAvatar(rect, onAvatarComplete);\n\nfunction onAvatarComplete(success:Boolean) {\n if(success) {\n trace(\"That user must love rectangles!\")\n } else {\n trace(\"Next time I'll try a triangle :(\")\n }\n}",
"language": "javascript",
"name": "ActionScript 3"
},
{
"code": "var base64PNG = 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVQYV2NgYAAAAAMAAWgmWQ0AAAAASUVORK5CYII=';\n\nkongregate.images.submitAvatar(base64PNG, function(success) {\n\tif (success) {\n \tconsole.log('That is a small avatar');\n }\n});",
"language": "javascript"
}
]
}
[/block]