{"record":{"id":"057ad0f207cb000d","repo":"Intervention/image","slug":"length-must-be-greater-than-or-equal-to-1","errorCode":null,"errorMessage":"Length must be greater than or equal to 1","messagePattern":"Length must be greater than or equal to 1","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Modifiers/SliceAnimationModifier.php","lineNumber":18,"sourceCode":"<?php\n\ndeclare(strict_types=1);\n\nnamespace Intervention\\Image\\Modifiers;\n\nuse Intervention\\Image\\Drivers\\SpecializableModifier;\nuse Intervention\\Image\\Exceptions\\InvalidArgumentException;\n\nclass SliceAnimationModifier extends SpecializableModifier\n{\n    /**\n     * @throws InvalidArgumentException\n     */\n    public function __construct(public int $offset = 0, public ?int $length = null)\n    {\n        if ($this->length !== null && $this->length <= 0) {\n            throw new InvalidArgumentException('Length must be greater than or equal to 1');\n        }\n    }\n}\n","sourceCodeStart":1,"sourceCodeEnd":22,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Modifiers/SliceAnimationModifier.php#L1-L22","documentation":"SliceAnimationModifier backs $image->sliceAnimation($offset, $length) on animated images. offset selects the frame to start from (0-based, no lower bound enforced here) and length is how many frames to keep, where null means 'until the end of the animation'. Because keeping zero or a negative number of frames is meaningless, the constructor throws InvalidArgumentException when length is a non-null int <= 0.","triggerScenarios":"Calling $image->sliceAnimation(0, 0), $image->sliceAnimation(5, -3), or new SliceAnimationModifier(offset: 0, length: 0). Length computed as e.g. $frameCount - $skip that ends up 0 or negative is a typical source.","commonSituations":"Frame-range math on animated GIFs/WebPs where the requested range is empty (offset beyond frame count making a computed length 0); passing a literal 0 intending 'no limit' instead of null; user-supplied frame counts that arrive as 0.","solutions":["Pass null for length when you want all remaining frames: $image->sliceAnimation(10)","Guard computed lengths: $length = $length > 0 ? $length : null","Validate user input for length as a positive integer before calling"],"exampleFix":"// before\n$image->sliceAnimation($offset, $framesLeft); // throws when $framesLeft is 0\n\n// after\n$image->sliceAnimation($offset, $framesLeft > 0 ? $framesLeft : null);","handlingStrategy":"validation","validationCode":"// Normalize length: null means 'all remaining frames'\n$length = isset($input['length']) ? (int) $input['length'] : null;\n$length = ($length !== null && $length > 0) ? $length : null;\n\n$image->sliceAnimation($offset, $length);","typeGuard":"function isValidSliceLength(mixed $length): bool\n{\n    return $length === null || (is_int($length) && $length >= 1);\n}","tryCatchPattern":"use Intervention\\Image\\Exceptions\\InvalidArgumentException;\n\ntry {\n    $image->sliceAnimation($offset, $length);\n} catch (InvalidArgumentException $e) {\n    // message: 'Length must be greater than or equal to 1'\n    $image->sliceAnimation($offset, null); // keep all remaining frames\n}","preventionTips":["Remember the API contract: null = rest of animation, 0/negative = error","Validate frame-range math against the frame count before slicing","Treat slice length as a positive-integer-or-null input field"],"tags":["animation","gif","webp","constructor","argument-validation","intervention-image"],"backgroundTag":"out-of-range-argument","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}