Intervention/image · error · Intervention\Image\Exceptions\InvalidArgumentException

Unable to parse RGB color from input "{input}"

Error message

Unable to parse RGB color from input "{input}"

What it means

Font::setStrokeWidth() validates that the text stroke width is an integer between 0 and 10 (in_array($width, range(0, 10))). Values outside that range — negative numbers or anything above 10 — throw this InvalidArgumentException. You reach it through the typography API, e.g. ->stroke($color, $width) when drawing text or configuring a font via FontFactory.

Source

Thrown at src/Color.php:73

     *
     * @throws InvalidArgumentException
     * @throws ColorException
     */
    public static function parse(string $input): ColorInterface
    {
        try {
            $color = InputHandler::usingDecoders([
                RgbStringColorDecoder::class,
                CmykStringColorDecoder::class,
                HsvStringColorDecoder::class,
                HslStringColorDecoder::class,
                OklabStringColorDecoder::class,
                OklchStringColorDecoder::class,
                NamedColorDecoder::class,
                RgbHexColorDecoder::class,
            ])->handle($input);
        } catch (NotSupportedException | DriverException $e) {
            throw new InvalidArgumentException(
                'Unable to parse RGB color from input "' . $input . '"',
                previous: $e,
            );
        }

        if (!$color instanceof ColorInterface) {
            throw new ColorException('Result must be instance of ' . self::class . ', got ' . $color::class);
        }

        return $color;
    }

    /**
     * Create new RGB color.
     *
     * @throws InvalidArgumentException
     * @throws DriverException
     */

View on GitHub (pinned to 5598b9e397)

Solutions

  1. Clamp the value before passing it: $width = max(0, min(10, $width))
  2. Validate user/designer input against the 0-10 range in your form/config layer
  3. If you truly need a thicker outline, layer it: draw the text multiple times with small offsets at width 10, or pre-render with another tool

Example fix

// before
$font->stroke('ff0000', $dynamicWidth); // throws when $dynamicWidth > 10

// after
$font->stroke('ff0000', max(0, min(10, (int) $dynamicWidth)));
Defensive patterns

Strategy: validation

Validate before calling

$width = (int) $requestedWidth;
if ($width < 0 || $width > 10) {
    $width = max(0, min(10, $width)); // clamp, or reject:
    // throw new \InvalidArgumentException('Stroke width must be 0-10');
}
$font->strokeWidth($width);

Type guard

function isValidStrokeWidth(mixed $width): bool
{
    return is_int($width) && $width >= 0 && $width <= 10;
}

Try / catch

use Intervention\Image\Exceptions\InvalidArgumentException;

try {
    $font->stroke($color, $dynamic);
} catch (InvalidArgumentException $e) {
    if (str_contains($e->getMessage(), 'stroke width')) {
        $font->stroke($color, 10); // degrade to maximum allowed stroke
    }
}

Prevention

When it happens

Trigger: $font->stroke('fff', 12) or a negative width like -1; ->strokeWidth(15) on a font; computing the width from a percentage of image size (e.g. intval($image->width() / 100)) without clamping, which exceeds 10 for wide images; copying a CSS text-shadow spread value (often 20+) into the stroke width.

Common situations: Dynamic stroke widths derived from image dimensions or font size that accidentally scale past 10; designers requesting thicker outlines than the library allows; porting code from a tool with unbounded stroke widths; unit tests asserting out-of-range values throw.

Understand the failure class

Related errors


AI-assisted analysis of Intervention/image@5598b9e397 (2026-08-23). Data as JSON: /api/errors/47cb13738aae42f5. Report an issue: GitHub.