Yalantis/uCrop · error · CImgArgumentException
save_graphicsmagick_external(): Specified filename is (null)
Error message
save_graphicsmagick_external(): Specified filename is (null).
What it means
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.
Source
Thrown at ucrop/src/main/jni/CImg.h:63713
"save_gzip_external(): Failed to save file '%s' with external command 'gzip'.",
cimg_instance,
filename);
std::remove(filename_tmp);
return *this;
}
//! Save image using GraphicsMagick's external binary.
/**
\param filename Filename, as a C-string.
\param quality Image quality (expressed in percent), when the file format supports it.
\note This method uses \c gm, an external executable binary provided by
<a href="http://www.graphicsmagick.org">GraphicsMagick</a>.
It must be installed for the method to succeed.
**/
const CImg<T>& save_graphicsmagick_external(const char *const filename, const unsigned int quality=100) const {
if (!filename)
throw CImgArgumentException(_cimg_instance
"save_graphicsmagick_external(): Specified filename is (null).",
cimg_instance);
if (is_empty()) { cimg::fempty(0,filename); return *this; }
if (_depth>1)
cimg::warn(_cimg_instance
"save_other(): File '%s', saving a volumetric image with an external call to "
"GraphicsMagick only writes the first image slice.",
cimg_instance,filename);
#ifdef cimg_use_png
#define _cimg_sge_extension1 "png"
#define _cimg_sge_extension2 "png"
#else
#define _cimg_sge_extension1 "pgm"
#define _cimg_sge_extension2 "ppm"
#endif
CImg<charT> command(1024), filename_tmp(256);
do {View on GitHub (pinned to f788b534b4)
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.
Example fix
// before
img.save_graphicsmagick_external(NULL);
// after
img.save_graphicsmagick_external("output.png", 100); Defensive patterns
Strategy: validation
Validate before calling
if (!fname || !*fname) fname = "output.png"; img.save_graphicsmagick_external(fname, /*quality*/90);
Type guard
bool validPath(const char *p) { return p != nullptr && p[0] != '\0'; } Try / catch
try { img.save_graphicsmagick_external(path.c_str()); }
catch (cimg_library::CImgArgumentException &e) { std::fprintf(stderr, "gm save: %s\n", e.what()); }
catch (cimg_library::CImgIOException &e) { std::fprintf(stderr, "graphicsmagick failed (installed?): %s\n", e.what()); } Prevention
- 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.
When it happens
Trigger: Calling save_graphicsmagick_external() with a null/default filename, or passing a char* that was never initialized.
Common situations: 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).
Related errors
- load_graphicsmagick_external(): Failed to load file '%s' wit
- save_pandore(): Specified filename is (null).
- save_raw(): Specified filename is (null).
- save_ffmpeg_external(): Specified filename is (null).
- save_gzip_external(): Specified filename is (null).
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/96f2ff5734ce9e99.
Report an issue: GitHub.