Yalantis/uCrop · error · CImgIOException
save_imagemagick_external(): Failed to save file '%s' with e
Error message
save_imagemagick_external(): Failed to save file '%s' with external command 'magick/convert'.
What it means
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.
Source
Thrown at ucrop/src/main/jni/CImg.h:63803
#define _cimg_sie_extension2 "ppm"
#endif
CImg<charT> command(1024), filename_tmp(256);
do {
cimg_snprintf(filename_tmp,filename_tmp._width,"%s%c%s.%s",cimg::temporary_path(),
cimg_file_separator,cimg::filenamerand(),_spectrum==1?_cimg_sie_extension1:_cimg_sie_extension2);
} while (cimg::path_exists(filename_tmp));
#ifdef cimg_use_png
save_png(filename_tmp);
#else
save_pnm(filename_tmp);
#endif
const char *magick_path = cimg::imagemagick_path();
cimg_snprintf(command,command._width,"\"%s\" -quality %u \"%s\" \"%s\"",
magick_path,quality,
CImg<charT>::string(filename_tmp)._system_strescape().data(),
CImg<charT>::string(filename)._system_strescape().data());
if (cimg::system(command,magick_path)!=0)
throw CImgIOException(_cimg_instance
"save_imagemagick_external(): Failed to save file '%s' with "
"external command 'magick/convert'.",
cimg_instance,
filename);
if (!cimg::path_exists(filename))
throw CImgIOException(_cimg_instance
"save_imagemagick_external(): Failed to save file '%s' with "
"external command 'magick/convert'.",
cimg_instance,
filename);
std::remove(filename_tmp);
return *this;
}
//! Save image as a Dicom file.
/**
\param filename Filename, as a C-string.View on GitHub (pinned to f788b534b4)
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.
Example fix
// before
img.save_imagemagick_external("out.tiff");
// after
try { img.save_imagemagick_external("out.tiff"); }
catch (CImgIOException&) { img.save_tiff("out.tiff"); } // or handle missing ImageMagick install Defensive patterns
Strategy: try-catch
Validate before calling
bool imAvailable() {
return std::system("magick -version > /dev/null 2>&1") == 0
|| std::system("convert -version > /dev/null 2>&1") == 0;
} Try / catch
try {
img.save_imagemagick_external(filename, quality);
} catch (CImgIOException& e) {
std::fprintf(stderr, "ImageMagick save failed: %s", e.what());
// choose native fallback or abort
} Prevention
- 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).
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- save_graphicsmagick_external(): Failed to save file '%s' wit
- save_other(): Failed to save file '%s'. Format is not native
- load_imagemagick_external(): Failed to load file '%s' with e
- save_medcon_external(): Failed to save file '%s' with extern
- load_magick(): Specified filename is (null).
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/3c342be63be1bbd8.
Report an issue: GitHub.