I didn't look at the function you call, but it would seem a string return would be the result, not an array? So get rid of the [0] on $avatar and see what happens.
EDIT: It is an array. I suggest you use...
PHP Code:
echo "<pre>";
print_r($avatar);
And see what you are getting in your array key wise and depth wise depending on the avatar you pull and the settings.