Yalantis/uCrop · error · CImgArgumentException

load_imagemagick_external(): Specified filename is (null) or

Error message

load_imagemagick_external(): Specified filename is (null) or does not exist.

What it means

load_imagemagick_external() validates that filename is non-null and exists as a file via cimg::is_file(); if not it throws CImgArgumentException before constructing the `convert` command. This is an argument precondition identical in shape to the graphicsmagick variant.

Source

Thrown at ucrop/src/main/jni/CImg.h:59769

      }
      load(filename_tmp);
      std::remove(filename_tmp);
      return *this;
    }

    //! Load gzipped image file, using external tool 'gunzip' \newinstance.
    static CImg<T> get_load_gzip_external(const char *const filename) {
      return CImg<T>().load_gzip_external(filename);
    }

    //! Load image using ImageMagick's external tool 'convert'.
    /**
       \param filename Filename, as a C-string.
    **/
    CImg<T>& load_imagemagick_external(const char *const filename) {
      if (!filename || !cimg::is_file(filename))
        throw CImgArgumentException(_cimg_instance
                                    "load_imagemagick_external(): Specified filename is (null) or does not exist.",
                                    cimg_instance);
      CImg<charT> command(1024), filename_tmp(256);
      const CImg<charT> s_filename = CImg<charT>::string(filename)._system_strescape();
      const char *magick_path = cimg::imagemagick_path();
#if cimg_OS==1
      if (cimg::posix_searchpath("magick") || cimg::posix_searchpath("convert")) {
        cimg_snprintf(command,command._width,"%s%s \"%s\" %s:-",
                      magick_path,
                      !cimg::strcasecmp(cimg::split_filename(filename),"pdf")?" -density 400x400":"",
                      s_filename.data(),
#ifdef cimg_use_png
                      "png"
#else
                      "pnm"
#endif
                      );
        std::FILE *file = popen(command,"r");

View on GitHub (pinned to f788b534b4)

Solutions

  1. Verify the file exists (stat / cimg::is_file) before calling and handle the miss
  2. Resolve the input to an absolute path and confirm with the caller
  3. Fix the pipeline step that should have created the file on disk
  4. If ImageMagick's `convert` binary is missing, configure cimg::imagemagick_path() or fall back to load_graphicsmagick_external()

Example fix

// before
img.load_imagemagick_external(path); // may be NULL / missing
// after
if (path && cimg::is_file(path)) {
  img.load_imagemagick_external(path);
} else {
  throw std::invalid_argument("file not found for imagemagick loader");
}
Defensive patterns

Strategy: validation

Validate before calling

if (!path || !cimg::is_file(path)) {
  throw std::invalid_argument("imagemagick loader input missing");
}
// also verify the tool exists:
if (!cimg::posix_searchpath("convert")) {
  throw std::runtime_error("ImageMagick convert not installed");
}

Type guard

bool ready_for_imagemagick(const char* f) { return f != nullptr && cimg::is_file(f); }

Try / catch

try {
  img.load_imagemagick_external(path);
} catch (CImgArgumentException& e) {
  // bad path: correct or fall back to built-in loader
  img.load(path);
}

Prevention

When it happens

Trigger: Calling load_imagemagick_external(NULL), a non-existent path, a directory, or a dangling symlink.

Common situations: ImageMagick path assumptions on hosts where only GraphicsMagick is installed (or vice versa); wrong relative paths; passing generated/virtual filenames that were never written to disk; Windows vs POSIX path separator mistakes.

Related errors


AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08). Data as JSON: /api/errors/c881e02a35644c9f. Report an issue: GitHub.