{"record":{"id":"5a3a34652588048a","repo":"Yalantis/uCrop","slug":"load-graphicsmagick-external-failed-to-load-fil","errorCode":null,"errorMessage":"load_graphicsmagick_external(): Failed to load file '%s' with external command 'gm'.","messagePattern":"load_graphicsmagick_external\\(\\): Failed to load file '(.+?)' with external command 'gm'\\.","errorType":"exception","errorClass":"CImgIOException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":59655,"sourceCode":"                      \"png\"\n#else\n                      \"pnm\"\n#endif\n                      );\n        std::FILE *file = popen(command,\"r\");\n        if (file) {\n          const unsigned int omode = cimg::exception_mode();\n          cimg::exception_mode(0);\n          try {\n#ifdef cimg_use_png\n            load_png(file);\n#else\n            load_pnm(file);\n#endif\n          } catch (...) {\n            pclose(file);\n            cimg::exception_mode(omode);\n            throw CImgIOException(_cimg_instance\n                                  \"load_graphicsmagick_external(): Failed to load file '%s' \"\n                                  \"with external command 'gm'.\",\n                                  cimg_instance,\n                                  filename);\n          }\n          pclose(file);\n          return *this;\n        }\n      }\n#endif\n      do {\n        cimg_snprintf(filename_tmp,filename_tmp._width,\"%s%c%s.%s\",\n                      cimg::temporary_path(),\n                      cimg_file_separator,\n                      cimg::filenamerand(),\n#ifdef cimg_use_png\n                      \"png\"\n#else","sourceCodeStart":59637,"sourceCodeEnd":59673,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L59637-L59673","documentation":"After spawning `gm convert <file> <tmpfile>` via popen and reading the resulting PNM/piped output, any exception raised while parsing the piped data is caught, the pipe closed, and a CImgIOException rethrown indicating GraphicsMagick failed to load the file. The failure is really 'gm ran but produced output CImg could not parse' or the gm process errored mid-stream.","triggerScenarios":"load_graphicsmagick_external() on POSIX when posix_searchpath(\"gm\") found the tool, popen() succeeded, but load_pnp/parsing of the stream threw (empty or malformed output from gm).","commonSituations":"GraphicsMagick installed but built without delegates (no support for the input format, e.g. missing JPEG/WebP delegate), producing empty output; gm emitting warnings to the stream; permission problems making gm read fail mid-run.","solutions":["Verify `gm convert input output.png` works from the shell to see gm's real error","Install the missing GraphicsMagick format delegates (e.g. libjpeg, libpng, libwebp dev packages) and rebuild gm","Fall back to load_imagemagick_external() or a native loader for the format","Check file readability/permissions for the user the process runs as"],"exampleFix":"// before\nimg.load_graphicsmagick_external(\"photo.jpg\"); // gm lacks jpeg delegate -> throws\n// after\nif (cimg::system(\"gm identify photo.jpg\") == 0) {\n  img.load_graphicsmagick_external(\"photo.jpg\");\n} else {\n  img.load_jpeg(\"photo.jpg\"); // built-in fallback\n}","handlingStrategy":"try-catch","validationCode":"// ensure gm can identify the file before using the external loader\nif (cimg::system(\"gm identify \\\"file.jpg\\\" > /dev/null 2>&1\") != 0) {\n  // gm unavailable or missing delegate: use built-in loader\n  img.load_jpeg(\"file.jpg\");\n} else {\n  img.load_graphicsmagick_external(\"file.jpg\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  img.load_graphicsmagick_external(filename);\n} catch (CImgIOException& e) {\n  cimg::warn(\"gm pipeline failed, falling back to native loader\");\n  img.load(filename); // native auto-detect\n}","preventionTips":["Install GraphicsMagick with all needed delegates (jpeg/png/webp)","Probe `gm identify` for format support at startup","Pin the gm version in your deployment image","Prefer CImg built-in loaders when the format is supported natively"],"tags":["cimg","graphicsmagick","external-tool","popen"],"backgroundTag":"external-tool-failed","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"}