@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator

Fix PHP 8.1 "implicit conversion from float to int" exception on certain avatar colors which blocks rendering user pages

Summary:
Since PHP 8.1, conversion from float to integer should be explicit.

https://wiki.php.net/rfc/implicit-float-int-deprecate

According to `phlog`, the alpha channel value of the automatically created user
avatar image for a new user account sometimes is a float.

Thus always `round()` the alpha channel value to be an integer.

Closes T15375

Test Plan: Applied this change, created five user accounts via http://phorge.localhost/people/new/standard/ , and each resulting alpha value in `PhabricatorFilesComposeAvatarBuiltinFile.php` was an integer according to `phlog` (see corresponding Maniphest task). Rendering of each new user page always succeeded.

Reviewers: O1 Blessed Committers, valerio.bozzolan

Reviewed By: O1 Blessed Committers, valerio.bozzolan

Subscribers: speck, tobiaswiese, valerio.bozzolan, Matthew, Cigaryno

Maniphest Tasks: T15375

Differential Revision: https://we.phorge.it/D25209

+10 -1
+10 -1
src/applications/files/builtin/PhabricatorFilesComposeAvatarBuiltinFile.php
··· 183 183 'image/png'); 184 184 } 185 185 186 + /** 187 + * Convert a color from RGBA to a value usable in PHP-GD. 188 + * Each RGB color should be expressed as an integer from 0 to 255. 189 + * The Alpha Channel should be expressed as a float from 0 to 1. 190 + * @param array $rgba array( int Red, int Green, int Blue, float Alpha ) 191 + * @return int 192 + */ 186 193 private static function rgba2gd($rgba) { 194 + // When working with a truecolor image, we can use bitwise operations 195 + // https://www.php.net/manual/en/function.imagecolorallocate.php#49168 187 196 $r = $rgba[0]; 188 197 $g = $rgba[1]; 189 198 $b = $rgba[2]; 190 199 $a = $rgba[3]; 191 - $a = (1 - $a) * 255; 200 + $a = round(((1 - $a) * 255), 0); 192 201 return ($a << 24) | ($r << 16) | ($g << 8) | $b; 193 202 } 194 203