{"record":{"id":"9e85779747d97d2f","repo":"Yalantis/uCrop","slug":"load-magick-unable-to-load-file-s-unless-lib","errorCode":null,"errorMessage":"load_magick(): Unable to load file '%s' unless libMagick++ is enabled.","messagePattern":"load_magick\\(\\): Unable to load file '(.+?)' unless libMagick\\+\\+ is enabled\\.","errorType":"exception","errorClass":"CImgIOException","httpStatus":null,"severity":"error","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":57322,"sourceCode":"        for (ulongT off = (ulongT)W*H; off; --off) {\n          *(ptr_r++) = (T)(pixels->red);\n          *(ptr_a++) = (T)(pixels->opacity);\n          ++pixels;\n        }\n      } break;\n      default : {\n        assign(W,H,1,1);\n        T *ptr_r = data(0,0,0,0);\n        Magick::PixelPacket *pixels = image.getPixels(0,0,W,H);\n        for (ulongT off = (ulongT)W*H; off; --off) {\n          *(ptr_r++) = (T)(pixels->red);\n          ++pixels;\n        }\n      }\n      }\n      return *this;\n#else\n      throw CImgIOException(_cimg_instance\n                            \"load_magick(): Unable to load file '%s' unless libMagick++ is enabled.\",\n                            cimg_instance,\n                            filename);\n#endif\n    }\n\n    //! Load image from a file, using Magick++ library \\newinstance.\n    static CImg<T> get_load_magick(const char *const filename) {\n      return CImg<T>().load_magick(filename);\n    }\n\n    //! Load image from a PNG file.\n    /**\n       \\param filename Filename, as a C-string.\n       \\param[out] bits_per_value Number of bits used to store a scalar value in the image file.\n    **/\n    CImg<T>& load_png(const char *const filename, unsigned int *const bits_per_value=0) {\n      return _load_png(0,filename,bits_per_value);","sourceCodeStart":57304,"sourceCodeEnd":57340,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L57304-L57340","documentation":"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.","triggerScenarios":"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).","commonSituations":"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).","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++."],"exampleFix":"// before\nimg.load_magick(\"photo.tiff\"); // throws: no libMagick++\n// after\nimg.load(\"photo.tiff\"); // routes to available codec\n// or build with: -Dcimg_use_magick and LOCAL_LDLIBS += -lMagick++-7.Q16HDRI","handlingStrategy":"fallback","validationCode":"#ifndef cimg_use_magick\n  // compile-time signal: load_magick is unusable in this build\n  constexpr bool kMagickAvailable = false;\n#else\n  constexpr bool kMagickAvailable = true;\n#endif","typeGuard":null,"tryCatchPattern":"try { img.load_magick(path); } catch (CImgIOException& e) { img.load(path); // fallback to auto-detected supported codec }","preventionTips":["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"],"tags":["imagemagick","missing-dependency","compile-time","cimg"],"backgroundTag":"missing-optional-dependency","analyzedSha":"f788b534b48c144edf786c8cddbf0e029e637804","analyzedAt":"2026-09-08T08:36:04.887Z","contentChangedAt":"2026-09-08T08:36:04.887Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}