Intervention/image · error · InvalidArgumentException

Invalid position argument. Must be int<0, max>

Error message

Invalid position argument. Must be int<0, max>

What it means

Error "Invalid position argument. Must be int<0, max>" thrown in Intervention/image.

Source

Thrown at src/Modifiers/RemoveAnimationModifier.php:20

declare(strict_types=1);

namespace Intervention\Image\Modifiers;

use Intervention\Image\Drivers\SpecializableModifier;
use Intervention\Image\Exceptions\InvalidArgumentException;
use Intervention\Image\Interfaces\FrameInterface;
use Intervention\Image\Interfaces\ImageInterface;

class RemoveAnimationModifier extends SpecializableModifier
{
    /**
     * @throws InvalidArgumentException
     */
    public function __construct(public int|string $position = 0)
    {
        if (is_int($this->position) && $this->position < 0) {
            throw new InvalidArgumentException('Invalid position argument. Must be int<0, max>');
        }
    }

    /**
     * @throws InvalidArgumentException
     */
    protected function selectedFrame(ImageInterface $image): FrameInterface
    {
        return $image->core()->frame($this->normalizePosition($image));
    }

    /**
     * Return the position of the selected frame as integer.
     *
     * @throws InvalidArgumentException
     */
    protected function normalizePosition(ImageInterface $image): int
    {

View on GitHub (pinned to 5598b9e397)

Solutions

  1. Pass a frame position of 0 or greater to removeAnimation()
  2. Use a percentage string like "50%" when addressing frames relatively
  3. Validate the position against the animation's frame count before calling

When it happens

Trigger: Thrown at src/Modifiers/RemoveAnimationModifier.php:20 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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