Forum

Avatar initials gen...
 
Notifications
Clear all

Avatar initials generation fails as size parameter is empty in url

1 Posts
2 Users
0 Reactions
25 Views
Posts: 5
Topic starter
(@cbd4-dk)
Member
Joined: 4 months ago

When using the Initials avatar mode in osTicket Awesome theme, the avatar generation fails with a fatal error:

Fatal error: Uncaught ValueError: imagecreatetruecolor(): Argument #1 ($width) must be greater than 0

Root cause:

The LocalAvatar::getUrl() method only adds the size parameter to the URL when $this->size is truthy. However, when getAvatar() is called without a size parameter (e.g., <?php echo $user->getAvatar(); ?> in templates), $this->size becomes an empty string "" rather than null.

When the empty string is passed to the avatar URL, PHP's (int) "" converts it to 0, which the GD library's imagecreatetruecolor() cannot accept.

Example problematic URL: avatar.php?uid=1&mode=initials&size=&name=Casper+

We are running 1.8.3


Posts: 1177
Admin
(@stevland)
Member
Joined: 2 months ago

Hi Carsten,

Great catch, and thank you for the thorough diagnosis. You've nailed the root cause exactly: when getAvatar() is called without a size parameter, the empty string slips through to imagecreatetruecolor() as zero.

This has been fixed in release 1.18.3-4, but if you'd rather not update right now, you can fix it in place by adding this line near the top of the render function in osta/php/avatar-initials.php, just before the image generation call:

$size = max((int)$size, 80);

Thanks for reporting this!


Reply
Share: