{"record":{"id":"e21c878e7e09effb","repo":"Intervention/image","slug":"unable-to-create-intervention-image-alignment-from","errorCode":null,"errorMessage":"Unable to create Intervention\\Image\\Alignment from \"{identifier}\"","messagePattern":"Unable to create Intervention\\\\Image\\\\Alignment from \"(.+?)\"","errorType":"exception","errorClass":"Intervention\\Image\\Exceptions\\InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Alignment.php","lineNumber":124,"sourceCode":"\n                'top_left',\n                'topleft',\n                'left-top',\n                'left_top',\n                'lefttop' => self::TOP_LEFT,\n\n                'middle',\n                'center-center',\n                'center_center',\n                'centercenter',\n                'center-middle',\n                'center_middle',\n                'centermiddle',\n                'middle-center',\n                'middle_center',\n                'middlecenter' => self::CENTER,\n\n                default => throw new InvalidArgumentException(\n                    'Unable to create ' . self::class . ' from \"' . $identifier . '\"',\n                ),\n            };\n        }\n\n        return $position;\n    }\n\n    /**\n     * Try to create position from given identifier or return null on failure.\n     */\n    public static function tryCreate(string|self $identifier): ?self\n    {\n        try {\n            return self::create($identifier);\n        } catch (InvalidArgumentException) {\n            return null;\n        }","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Alignment.php#L106-L142","documentation":"Intervention Image throws this FileNotFoundException when you pass an SplFileInfo object to ImageManager::read() (or any API that resolves file paths, e.g. font loading) and the directory stored in the SplFileInfo exists but the basename does not. The check happens in filePathFromSplFileInfoOrFail() via file_exists() on $splFileInfo->getPathname(), after the directory check has already passed. It means the object points at a path that is no longer (or never was) present on disk.","triggerScenarios":"ImageManager::read(new SplFileInfo('uploads/photo.png')) where 'uploads/' exists but 'photo.png' does not; passing an SplFileInfo built from a stale or misspelled filename; an SplFileInfo captured earlier whose file was deleted or moved by another process (temp upload already moved, queue worker races); passing a relative basename when the object was constructed without the directory.","commonSituations":"Upload pipelines where the file is renamed/moved between validation and image processing; typos or missing file extensions in paths built from user input; concurrent workers processing the same file; code migrated from passing strings (readableFilePathOrFail) to SplFileInfo objects where the path semantics differ slightly.","solutions":["Check file_exists($splFileInfo->getPathname()) before calling read() and fail gracefully with your own error handling","Verify the actual path the object carries: var_dump($splFileInfo->getPathname()) and compare with what is on disk (watch for relative vs absolute paths and cwd differences between CLI and web)","If the file may be moved concurrently, copy it to a private temp location and pass an SplFileInfo for that copy","If the file should exist, re-upload or regenerate it before retrying"],"exampleFix":"// before\n$image = $manager->read(new SplFileInfo($userPath)); // FileNotFoundException when file is gone\n\n// after\n$info = new SplFileInfo($userPath);\nif (!file_exists($info->getPathname())) {\n    throw new RuntimeException('Uploaded image is no longer available: ' . $info->getPathname());\n}\n$image = $manager->read($info);","handlingStrategy":"validation","validationCode":"$info = $splFileInfo instanceof \\SplFileInfo ? new \\SplFileInfo($splFileInfo->getPathname()) : $splFileInfo;\nif (!$info instanceof \\SplFileInfo || !file_exists($info->getPathname())) {\n    // reject before ImageManager::read()\n    throw new \\RuntimeException('Image file not found: ' . ($info ? $info->getPathname() : 'n/a'));\n}\n$image = $manager->read($info);","typeGuard":"/** @throws \\LogicException when the SplFileInfo target is not an existing regular file */\nfunction assertExistingFile(\\SplFileInfo $info): void\n{\n    if (!file_exists($info->getPathname()) || !$info->isFile()) {\n        throw new \\LogicException('Not an existing regular file: ' . $info->getPathname());\n    }\n}","tryCatchPattern":"use Intervention\\Image\\Exceptions\\FileNotFoundException;\n\ntry {\n    $image = $manager->read($file);\n} catch (FileNotFoundException $e) {\n    // log the exact missing path from the message and report a friendly error\n    logger()->warning($e->getMessage());\n    abort(404, 'Image not available');\n}","preventionTips":["Treat any user-supplied path as untrusted: resolve it with realpath() against an allowed base directory before wrapping it in SplFileInfo","Process uploads from a private copy you own so other code cannot delete the file mid-request","In UIs that list images, check file existence when listing rather than only when processing"],"tags":["file-not-found","splfileinfo","input-validation","intervention-image"],"backgroundTag":"file-not-found","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}