mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 00:42:41 +01:00
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
This commit is contained in:
parent
4d97195397
commit
c2856b479f
1 changed files with 10 additions and 1 deletions
|
@ -183,12 +183,21 @@ final class PhabricatorFilesComposeAvatarBuiltinFile
|
|||
'image/png');
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a color from RGBA to a value usable in PHP-GD.
|
||||
* Each RGB color should be expressed as an integer from 0 to 255.
|
||||
* The Alpha Channel should be expressed as a float from 0 to 1.
|
||||
* @param array $rgba array( int Red, int Green, int Blue, float Alpha )
|
||||
* @return int
|
||||
*/
|
||||
private static function rgba2gd($rgba) {
|
||||
// When working with a truecolor image, we can use bitwise operations
|
||||
// https://www.php.net/manual/en/function.imagecolorallocate.php#49168
|
||||
$r = $rgba[0];
|
||||
$g = $rgba[1];
|
||||
$b = $rgba[2];
|
||||
$a = $rgba[3];
|
||||
$a = (1 - $a) * 255;
|
||||
$a = round(((1 - $a) * 255), 0);
|
||||
return ($a << 24) | ($r << 16) | ($g << 8) | $b;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue