{"record":{"id":"96f2ff5734ce9e99","repo":"Yalantis/uCrop","slug":"save-graphicsmagick-external-specified-filename","errorCode":null,"errorMessage":"save_graphicsmagick_external(): Specified filename is (null).","messagePattern":"save_graphicsmagick_external\\(\\): Specified filename is \\(null\\)\\.","errorType":"exception","errorClass":"CImgArgumentException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":63713,"sourceCode":"                              \"save_gzip_external(): Failed to save file '%s' with external command 'gzip'.\",\n                              cimg_instance,\n                              filename);\n\n      std::remove(filename_tmp);\n      return *this;\n    }\n\n    //! Save image using GraphicsMagick's external binary.\n    /**\n       \\param filename Filename, as a C-string.\n       \\param quality Image quality (expressed in percent), when the file format supports it.\n       \\note This method uses \\c gm, an external executable binary provided by\n         <a href=\"http://www.graphicsmagick.org\">GraphicsMagick</a>.\n       It must be installed for the method to succeed.\n    **/\n    const CImg<T>& save_graphicsmagick_external(const char *const filename, const unsigned int quality=100) const {\n      if (!filename)\n        throw CImgArgumentException(_cimg_instance\n                                    \"save_graphicsmagick_external(): Specified filename is (null).\",\n                                    cimg_instance);\n      if (is_empty()) { cimg::fempty(0,filename); return *this; }\n      if (_depth>1)\n        cimg::warn(_cimg_instance\n                   \"save_other(): File '%s', saving a volumetric image with an external call to \"\n                   \"GraphicsMagick only writes the first image slice.\",\n                   cimg_instance,filename);\n\n#ifdef cimg_use_png\n#define _cimg_sge_extension1 \"png\"\n#define _cimg_sge_extension2 \"png\"\n#else\n#define _cimg_sge_extension1 \"pgm\"\n#define _cimg_sge_extension2 \"ppm\"\n#endif\n      CImg<charT> command(1024), filename_tmp(256);\n      do {","sourceCodeStart":63695,"sourceCodeEnd":63731,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L63695-L63731","documentation":"save_graphicsmagick_external() converts/saves the image by invoking the external gm (GraphicsMagick) binary, so a non-null filename is mandatory. It throws CImgArgumentException when the filename is null. gm must be installed for the conversion to succeed.","triggerScenarios":"Calling save_graphicsmagick_external() with a null/default filename, or passing a char* that was never initialized.","commonSituations":"Path built from missing configuration; forgetting the argument since quality has a default value; calling this format on systems where no gm binary exists (the null check fires first).","solutions":["Pass a valid filename: img.save_graphicsmagick_external(\"out.jpg\", 90).","Default the filename when null before calling.","Prefer CImg's built-in save formats (which dispatch internally) if GraphicsMagick isn't available."],"exampleFix":"// before\nimg.save_graphicsmagick_external(NULL);\n// after\nimg.save_graphicsmagick_external(\"output.png\", 100);","handlingStrategy":"validation","validationCode":"if (!fname || !*fname) fname = \"output.png\";\nimg.save_graphicsmagick_external(fname, /*quality*/90);","typeGuard":"bool validPath(const char *p) { return p != nullptr && p[0] != '\\0'; }","tryCatchPattern":"try { img.save_graphicsmagick_external(path.c_str()); }\ncatch (cimg_library::CImgArgumentException &e) { std::fprintf(stderr, \"gm save: %s\\n\", e.what()); }\ncatch (cimg_library::CImgIOException &e) { std::fprintf(stderr, \"graphicsmagick failed (installed?): %s\\n\", e.what()); }","preventionTips":["Always supply an explicit output filename with a GraphicsMagick-supported extension.","Check gm availability (cimg::graphicsmagick_path()) before feature use.","Route all external saves through one validated helper function."],"tags":["cimg","null-argument","graphicsmagick","external-tool","file-save"],"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"}