Skip to content

Bug: InvalidArgumentException (Invalid value for alignment) because 'middle' does not exist in Intervention v4 Alignment Enum #192

@adeiming

Description

@adeiming

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions