Yalantis/uCrop · error · CImgIOException
load_magick(): Unable to load file '%s' unless libMagick++ i
Error message
load_magick(): Unable to load file '%s' unless libMagick++ is enabled.
What it means
load_magick() only functions when CImg was compiled with cimg_use_magick, enabling the libMagick++ code path. In the #else branch it unconditionally throws CImgIOException, since ImageMagick-dependent decoding is unavailable. The file may be perfectly valid; the library build simply cannot handle it.
Source
Thrown at ucrop/src/main/jni/CImg.h:57322
for (ulongT off = (ulongT)W*H; off; --off) {
*(ptr_r++) = (T)(pixels->red);
*(ptr_a++) = (T)(pixels->opacity);
++pixels;
}
} break;
default : {
assign(W,H,1,1);
T *ptr_r = data(0,0,0,0);
Magick::PixelPacket *pixels = image.getPixels(0,0,W,H);
for (ulongT off = (ulongT)W*H; off; --off) {
*(ptr_r++) = (T)(pixels->red);
++pixels;
}
}
}
return *this;
#else
throw CImgIOException(_cimg_instance
"load_magick(): Unable to load file '%s' unless libMagick++ is enabled.",
cimg_instance,
filename);
#endif
}
//! Load image from a file, using Magick++ library \newinstance.
static CImg<T> get_load_magick(const char *const filename) {
return CImg<T>().load_magick(filename);
}
//! Load image from a PNG file.
/**
\param filename Filename, as a C-string.
\param[out] bits_per_value Number of bits used to store a scalar value in the image file.
**/
CImg<T>& load_png(const char *const filename, unsigned int *const bits_per_value=0) {
return _load_png(0,filename,bits_per_value);View on GitHub (pinned to f788b534b4)
Solutions
- Install ImageMagick development headers, define cimg_use_magick, and link Magick++/MagickCore, then rebuild.
- Or avoid load_magick entirely and use a format-specific loader (load_png, load_jpeg) or load() which auto-detects based on available codecs.
- On Android, convert the image outside the app or bundle a supported codec instead of shipping Magick++.
Example fix
// before
img.load_magick("photo.tiff"); // throws: no libMagick++
// after
img.load("photo.tiff"); // routes to available codec
// or build with: -Dcimg_use_magick and LOCAL_LDLIBS += -lMagick++-7.Q16HDRI Defensive patterns
Strategy: fallback
Validate before calling
#ifndef cimg_use_magick // compile-time signal: load_magick is unusable in this build constexpr bool kMagickAvailable = false; #else constexpr bool kMagickAvailable = true; #endif
Try / catch
try { img.load_magick(path); } catch (CImgIOException& e) { img.load(path); // fallback to auto-detected supported codec } Prevention
- Gate Magick-dependent calls behind #ifdef cimg_use_magick in your own code
- Use CImg::load() with format auto-detection instead of load_magick when possible
- Document build requirements (ImageMagick dev + cimg_use_magick) for Magick paths
When it happens
Trigger: Calling load_magick(filename) in a build where cimg_use_magick was not defined (no #define cimg_use_magick before including CImg.h and no Magick++ link).
Common situations: Default CImg builds (no ImageMagick dev package installed), Android NDK builds (like this ucrop JNI) where Magick++ was never added to the makefile, or defining cimg_use_magick but not linking Magick++ (link error precedes this).
Understand the failure class
Background: "X is not installed. Please install it with pip install Y": missing optional dependency errors — ImportError/ValueError raised when a library's optional extra was never installed — this error's family across 22 libraries.
Related errors
- load_gif_external(): Failed to open file '%s'.
- load_magick(): Specified filename is (null).
- load_imagemagick_external(): Specified filename is (null) or
- load_imagemagick_external(): Failed to load file '%s' with e
- load_camera(): This function requires features from the Open
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/9e85779747d97d2f.
Report an issue: GitHub.