{"record":{"id":"c881e02a35644c9f","repo":"Yalantis/uCrop","slug":"load-imagemagick-external-specified-filename-is","errorCode":null,"errorMessage":"load_imagemagick_external(): Specified filename is (null) or does not exist.","messagePattern":"load_imagemagick_external\\(\\): Specified filename is \\(null\\) or does not exist\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":59769,"sourceCode":"\n      }\n      load(filename_tmp);\n      std::remove(filename_tmp);\n      return *this;\n    }\n\n    //! Load gzipped image file, using external tool 'gunzip' \\newinstance.\n    static CImg<T> get_load_gzip_external(const char *const filename) {\n      return CImg<T>().load_gzip_external(filename);\n    }\n\n    //! Load image using ImageMagick's external tool 'convert'.\n    /**\n       \\param filename Filename, as a C-string.\n    **/\n    CImg<T>& load_imagemagick_external(const char *const filename) {\n      if (!filename || !cimg::is_file(filename))\n        throw CImgArgumentException(_cimg_instance\n                                    \"load_imagemagick_external(): Specified filename is (null) or does not exist.\",\n                                    cimg_instance);\n      CImg<charT> command(1024), filename_tmp(256);\n      const CImg<charT> s_filename = CImg<charT>::string(filename)._system_strescape();\n      const char *magick_path = cimg::imagemagick_path();\n#if cimg_OS==1\n      if (cimg::posix_searchpath(\"magick\") || cimg::posix_searchpath(\"convert\")) {\n        cimg_snprintf(command,command._width,\"%s%s \\\"%s\\\" %s:-\",\n                      magick_path,\n                      !cimg::strcasecmp(cimg::split_filename(filename),\"pdf\")?\" -density 400x400\":\"\",\n                      s_filename.data(),\n#ifdef cimg_use_png\n                      \"png\"\n#else\n                      \"pnm\"\n#endif\n                      );\n        std::FILE *file = popen(command,\"r\");","sourceCodeStart":59751,"sourceCodeEnd":59787,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L59751-L59787","documentation":"load_imagemagick_external() validates that filename is non-null and exists as a file via cimg::is_file(); if not it throws CImgArgumentException before constructing the `convert` command. This is an argument precondition identical in shape to the graphicsmagick variant.","triggerScenarios":"Calling load_imagemagick_external(NULL), a non-existent path, a directory, or a dangling symlink.","commonSituations":"ImageMagick path assumptions on hosts where only GraphicsMagick is installed (or vice versa); wrong relative paths; passing generated/virtual filenames that were never written to disk; Windows vs POSIX path separator mistakes.","solutions":["Verify the file exists (stat / cimg::is_file) before calling and handle the miss","Resolve the input to an absolute path and confirm with the caller","Fix the pipeline step that should have created the file on disk","If ImageMagick's `convert` binary is missing, configure cimg::imagemagick_path() or fall back to load_graphicsmagick_external()"],"exampleFix":"// before\nimg.load_imagemagick_external(path); // may be NULL / missing\n// after\nif (path && cimg::is_file(path)) {\n  img.load_imagemagick_external(path);\n} else {\n  throw std::invalid_argument(\"file not found for imagemagick loader\");\n}","handlingStrategy":"validation","validationCode":"if (!path || !cimg::is_file(path)) {\n  throw std::invalid_argument(\"imagemagick loader input missing\");\n}\n// also verify the tool exists:\nif (!cimg::posix_searchpath(\"convert\")) {\n  throw std::runtime_error(\"ImageMagick convert not installed\");\n}","typeGuard":"bool ready_for_imagemagick(const char* f) { return f != nullptr && cimg::is_file(f); }","tryCatchPattern":"try {\n  img.load_imagemagick_external(path);\n} catch (CImgArgumentException& e) {\n  // bad path: correct or fall back to built-in loader\n  img.load(path);\n}","preventionTips":["Stat inputs and probe for the convert binary before external-tool loaders","Set cimg::imagemagick_path() when convert is not on PATH","Use absolute paths; avoid NULL-able filename variables","Provide a built-in-loader fallback for supported formats"],"tags":["cimg","imagemagick","argument-validation","file-not-found"],"backgroundTag":"null-argument","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}