{"record":{"id":"3d57f02abeec12de","repo":"Intervention/image","slug":"the-specified-position-x-y-is-not-within-th","errorCode":null,"errorMessage":"The specified position ({x}, {y}) is not within the image area","messagePattern":"The specified position \\((.+?), (.+?)\\) is not within the image area","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Drivers/Gd/Analyzers/PixelColorAnalyzer.php","lineNumber":46,"sourceCode":"     */\n    public function analyze(ImageInterface $image): mixed\n    {\n        $colorProcessor = $this->driver()->colorProcessor($image);\n\n        return $this->colorAt($colorProcessor, $image->core()->frame($this->frame));\n    }\n\n    /**\n     * @throws InvalidArgumentException\n     * @throws AnalyzerException\n     */\n    protected function colorAt(ColorProcessorInterface $processor, FrameInterface $frame): ColorInterface\n    {\n        $gd = $frame->native();\n        $index = @imagecolorat($gd, $this->x, $this->y);\n\n        if (!is_int($index)) {\n            throw new InvalidArgumentException(\n                'The specified position (' . $this->x . ', ' . $this->y . ') is not within the image area',\n            );\n        }\n\n        try {\n            $colors = imagecolorsforindex($gd, $index);\n        } catch (ValueError) {\n            throw new AnalyzerException(\n                'The specified index is outside of the range',\n            );\n        }\n\n        return $processor->import($colors);\n    }\n}\n","sourceCodeStart":28,"sourceCodeEnd":62,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Drivers/Gd/Analyzers/PixelColorAnalyzer.php#L28-L62","documentation":"The GD pixel analyzer calls imagecolorat() at the requested coordinates; it returns no index when the position lies outside the image, so the library reports the offending (x, y). Coordinates are zero-based and must satisfy 0 <= x < width and 0 <= y < height.","triggerScenarios":"$image->pickColor($x, $y) with $x >= $image->width() or $y >= $image->height(), negative coordinates, or coordinates computed against a different image's dimensions; loops using <= width instead of < width.","commonSituations":"Resize/crop pipelines computing coordinates from stale dimensions; hardcoded pixel probes on user uploads of varying sizes; off-by-one loop bounds.","solutions":["Clamp coordinates before picking: $x = max(0, min($x, $image->width() - 1))","Validate coordinates against width()/height() at the boundary and reject or default out-of-range values","Fix off-by-one in loops: iterate x < width, never x <= width"],"exampleFix":"// before\n$color = $image->pickColor($x, $y);\n\n// after\n$x = max(0, min($x, $image->width() - 1));\n$y = max(0, min($y, $image->height() - 1));\n$color = $image->pickColor($x, $y);","handlingStrategy":"validation","validationCode":"$x = max(0, min($x, $image->width() - 1));\n$y = max(0, min($y, $image->height() - 1));","typeGuard":null,"tryCatchPattern":"try {\n    $color = $image->pickColor($x, $y);\n} catch (\\Intervention\\Image\\Exceptions\\InvalidArgumentException $e) {\n    $color = $image->pickColor(0, 0);\n}","preventionTips":["Clamp coordinates against width()/height() before every pickColor()","Use < width in loops, never <= width","Recompute probe coordinates after every resize/crop"],"tags":["pixel","coordinates","out-of-bounds","gd","validation"],"backgroundTag":"pixel-out-of-bounds","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}