Bug Description
When using "laravolt/avatar": "^6.5" which integrates with Intervention Image v4, generating an avatar throws an Intervention\Image\Exceptions\InvalidArgumentException: Invalid value for alignment.
Root Cause
Inside src/Avatar.php at line 373, Laravolt hardcodes the font alignment with:
$font->align('center', 'middle');
The second argument ('middle') is passed to Intervention v4's vertical alignment processor. Inside Intervention v4's Font.php, it strictly validates the value using native PHP Enum matching:
Alignment::from($alignment)
However, in Intervention Image v4, the Alignment Enum does not contain a 'middle' case (it only has 'center', 'top', 'bottom', etc.). Because 'middle' is missing from the Enum cases, PHP throws a ValueError, which causes Intervention to bail out with the InvalidArgumentException.
Proposed Fix
Change the hardcoded vertical alignment parameter from 'middle' to 'center' inside src/Avatar.php to comply with the strict Intervention v4 Alignment Enum, or separate them using the native v4 methods:
// Inside buildAvatar() method in src/Avatar.php
return $this->image->text($this->getInitials(), $x, $y, function (FontFactory $font) {
$font->size($this->fontSize);
$font->color($this->foreground);
// $font->align('center', 'middle');
$font->align('center', 'center'); // Changed from 'middle' to 'center' to match v4 Enum
});
Environment
- laravolt/avatar Version: 6.5+
- intervention/image Version: 4.x
Bug Description
When using
"laravolt/avatar": "^6.5"which integrates with Intervention Image v4, generating an avatar throws anIntervention\Image\Exceptions\InvalidArgumentException: Invalid value for alignment.Root Cause
Inside
src/Avatar.phpat line 373, Laravolt hardcodes the font alignment with:The second argument (
'middle') is passed to Intervention v4's vertical alignment processor. Inside Intervention v4'sFont.php, it strictly validates the value using native PHP Enum matching:However, in Intervention Image v4, the
AlignmentEnum does not contain a'middle'case (it only has'center','top','bottom', etc.). Because'middle'is missing from the Enum cases, PHP throws aValueError, which causes Intervention to bail out with theInvalidArgumentException.Proposed Fix
Change the hardcoded vertical alignment parameter from
'middle'to'center'insidesrc/Avatar.phpto comply with the strict Intervention v4AlignmentEnum, or separate them using the native v4 methods:Environment