{"record":{"id":"3c342be63be1bbd8","repo":"Yalantis/uCrop","slug":"save-imagemagick-external-failed-to-save-file","errorCode":null,"errorMessage":"save_imagemagick_external(): Failed to save file '%s' with external command 'magick/convert'.","messagePattern":"save_imagemagick_external\\(\\): Failed to save file '(.+?)' with external command 'magick/convert'\\.","errorType":"exception","errorClass":"CImgIOException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":63803,"sourceCode":"#define _cimg_sie_extension2 \"ppm\"\n#endif\n      CImg<charT> command(1024), filename_tmp(256);\n      do {\n        cimg_snprintf(filename_tmp,filename_tmp._width,\"%s%c%s.%s\",cimg::temporary_path(),\n                      cimg_file_separator,cimg::filenamerand(),_spectrum==1?_cimg_sie_extension1:_cimg_sie_extension2);\n      } while (cimg::path_exists(filename_tmp));\n#ifdef cimg_use_png\n      save_png(filename_tmp);\n#else\n      save_pnm(filename_tmp);\n#endif\n      const char *magick_path = cimg::imagemagick_path();\n      cimg_snprintf(command,command._width,\"\\\"%s\\\" -quality %u \\\"%s\\\" \\\"%s\\\"\",\n                    magick_path,quality,\n                    CImg<charT>::string(filename_tmp)._system_strescape().data(),\n                    CImg<charT>::string(filename)._system_strescape().data());\n      if (cimg::system(command,magick_path)!=0)\n        throw CImgIOException(_cimg_instance\n                              \"save_imagemagick_external(): Failed to save file '%s' with \"\n                              \"external command 'magick/convert'.\",\n                              cimg_instance,\n                              filename);\n      if (!cimg::path_exists(filename))\n        throw CImgIOException(_cimg_instance\n                              \"save_imagemagick_external(): Failed to save file '%s' with \"\n                              \"external command 'magick/convert'.\",\n                              cimg_instance,\n                              filename);\n\n      std::remove(filename_tmp);\n      return *this;\n    }\n\n    //! Save image as a Dicom file.\n    /**\n       \\param filename Filename, as a C-string.","sourceCodeStart":63785,"sourceCodeEnd":63821,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L63785-L63821","documentation":"CImg::save_imagemagick_external() invokes the ImageMagick 'magick' or 'convert' executable to write formats CImg cannot handle natively. This error is thrown when the external command returns a non-zero exit status. The image was not saved.","triggerScenarios":"Calling save_imagemagick_external(filename, quality) when: imagemagick_path() resolves to a missing or wrong binary; 'magick'/'convert' fails due to unsupported format, bad options, insufficient memory, or unreadable temp file; security policies (e.g. ImageMagick policy.xml) block the format.","commonSituations":"ImageMagick not installed in the deployment container; ImageMagick 7 renamed the binary to 'magick' while older scripts expect 'convert' (or vice versa); policy.xml restricting write formats; low-memory environments failing on large images.","solutions":["Verify cimg::imagemagick_path() points to a working 'magick' or 'convert' binary and run the constructed command manually to see the actual error.","Install ImageMagick or fix the IMAGEMAGICK path configuration.","Check ImageMagick policy.xml for delegates/formats that are disabled.","Confirm the requested output format is supported by the installed ImageMagick version.","Fall back to CImg native save() or another installed tool."],"exampleFix":"// before\nimg.save_imagemagick_external(\"out.tiff\");\n// after\ntry { img.save_imagemagick_external(\"out.tiff\"); }\ncatch (CImgIOException&) { img.save_tiff(\"out.tiff\"); } // or handle missing ImageMagick install","handlingStrategy":"try-catch","validationCode":"bool imAvailable() {\n  return std::system(\"magick -version > /dev/null 2>&1\") == 0\n      || std::system(\"convert -version > /dev/null 2>&1\") == 0;\n}","typeGuard":null,"tryCatchPattern":"try {\n  img.save_imagemagick_external(filename, quality);\n} catch (CImgIOException& e) {\n  std::fprintf(stderr, \"ImageMagick save failed: %s\", e.what());\n  // choose native fallback or abort\n}","preventionTips":["Install ImageMagick and confirm 'magick' or 'convert' runs in the deployment environment.","Run the failing command manually to see ImageMagick's own error text.","Review policy.xml for disabled coders/delegates.","Remember ImageMagick 6 vs 7 binary naming differences (convert vs magick)."],"tags":["io","external-command","imagemagick","image-save"],"backgroundTag":"command-not-found","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"}