Yalantis/uCrop · error · CImgIOException
load_dcraw_external(): Failed to load file '%s' with externa
Error message
load_dcraw_external(): Failed to load file '%s' with external command 'dcraw'.
What it means
On Unix, load_dcraw_external() opens a pipe 'dcraw -w -4 -c "<file>"' with popen() and decodes the PNM stream from dcraw's stdout. If load_pnm throws while reading that stream, this CImgIOException is thrown: dcraw ran but its output could not be parsed as an image.
Source
Thrown at ucrop/src/main/jni/CImg.h:59977
**/
CImg<T>& load_dcraw_external(const char *const filename) {
if (!filename || !cimg::is_file(filename))
throw CImgArgumentException(_cimg_instance
"load_dcraw_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();
#if cimg_OS==1
cimg_snprintf(command,command._width,"%s -w -4 -c \"%s\"",
cimg::dcraw_path(),s_filename.data());
std::FILE *file = popen(command,"r");
if (file) {
const unsigned int omode = cimg::exception_mode();
cimg::exception_mode(0);
try { load_pnm(file); } catch (...) {
pclose(file);
cimg::exception_mode(omode);
throw CImgIOException(_cimg_instance
"load_dcraw_external(): Failed to load file '%s' with external command 'dcraw'.",
cimg_instance,
filename);
}
pclose(file);
return *this;
}
#endif
do {
cimg_snprintf(filename_tmp,filename_tmp._width,"%s%c%s.ppm",
cimg::temporary_path(),cimg_file_separator,cimg::filenamerand());
} while (cimg::path_exists(filename_tmp));
cimg_snprintf(command,command._width,"\"%s\" -w -4 -c \"%s\" > \"%s\"",
cimg::dcraw_path(),s_filename.data(),CImg<charT>::string(filename_tmp)._system_strescape().data());
cimg::system(command,cimg::dcraw_path());
if (!cimg::path_exists(filename_tmp)) {
cimg::fclose(cimg::fopen(filename,"r"));
throw CImgIOException(_cimg_instanceView on GitHub (pinned to f788b534b4)
Solutions
- Verify dcraw exists: run 'dcraw' in the same environment; install it (or switch to LibRaw) if missing.
- Run 'dcraw -w -4 -c file.CR2 > out.ppm' manually to see dcraw's actual error message.
- Check the RAW file is complete and from a supported camera (update dcraw or use LibRaw for newer models).
- Confirm the process user can read the RAW file.
- Convert the RAW yourself with LibRaw/dcraw to PPM/TIFF and load it with CImg::load(), giving you direct access to the tool's exit status.
Example fix
// before
img.load_dcraw_external("IMG_0001.CR2");
// after
try { img.load_dcraw_external("IMG_0001.CR2"); }
catch (CImgIOException&) {
if (cimg::system("dcraw -w -4 -c IMG_0001.CR2 > IMG_0001.ppm"))
throw std::runtime_error("dcraw failed/missing for IMG_0001.CR2");
img.load("IMG_0001.ppm");
} Defensive patterns
Strategy: try-catch
Validate before calling
if (!cimg::is_file(path)) throw std::invalid_argument("RAW missing");
if (cimg::system("dcraw --version","dcraw")!=0 && cimg::system("dcraw","dcraw")!=0)
throw std::runtime_error("dcraw not installed"); Type guard
bool dcrawAvailable(){ return cimg::system("dcraw","dcraw")==0 || cimg::system("dcraw -V","dcraw")==0; } Try / catch
try { img.load_dcraw_external(path); }
catch (CImgIOException& e) {
// decode yourself to get dcraw's real exit status
if (cimg::system("dcraw -w -4 -c <file> > out.ppm"))
throw std::runtime_error("dcraw failed or unsupported RAW format");
img.load("out.ppm");
} Prevention
- Install dcraw (or migrate to LibRaw) in deployment images
- Check camera support for newer RAW formats
- Verify RAW file integrity after transfers
- Avoid popen-based external loads where exit status matters — render to a file instead
When it happens
Trigger: Calling load_dcraw_external(filename) on Unix where dcraw starts but emits an invalid or empty PNM stream — dcraw not really installed (shell printed 'command not found' into the pipe), unsupported camera RAW format, corrupted RAW file, or dcraw erroring mid-conversion.
Common situations: dcraw missing on the deployment machine so popen succeeds but the pipe yields only a shell error message; new camera formats dcraw does not support (project dormant — LibRaw is maintained instead); truncated RAW transfers from memory cards.
Related errors
- load_pdf_external(): Failed to load file '%s' with external
- load_dcraw_external(): Specified filename is (null) or does
- load_pnm(): PNM header not found in file '%s'.
- load_pnm(): WIDTH and HEIGHT fields undefined in file '%s'.
- load_pnm(): Specified image dimensions in file '%s' exceed f
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/c4e05e899617c383.
Report an issue: GitHub.