Yalantis/uCrop · error · CImgIOException

load_jxl(): Unable to load data from '(FILE*)' unless libjxl

Error message

load_jxl(): Unable to load data from '(FILE*)' unless libjxl is enabled.

What it means

When CImg is built without libjxl (cimg_use_jxl undefined), JPEG XL decoding from an already-open FILE* cannot proceed, since the fallback loader needs a filename. CImg throws CImgIOException instructing that libjxl must be enabled.

Source

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

    //! Load image from a JPEG XL file \overloading.
    CImg<T>& load_jxl(std::FILE *const file) {
      return _load_jxl(file,0);
    }

    //! Load image from a JPEG XL file \newinstance.
    static CImg<T> get_load_jxl(std::FILE *const file) {
      return CImg<T>().load_jxl(file);
    }

    CImg<T>& _load_jxl(std::FILE *const file, const char *const filename) {
      if (!file && !filename)
        throw CImgArgumentException(_cimg_instance
                                    "load_jxl(): Specified filename is (null).",
                                    cimg_instance);

#ifndef cimg_use_jxl
      if (file)
        throw CImgIOException(_cimg_instance
                              "load_jxl(): Unable to load data from '(FILE*)' unless libjxl is enabled.",
                              cimg_instance);
      else return load_other(filename);
#else
      const char *nfilename = filename;
      std::FILE *nfile = file?file:cimg::fopen(nfilename,"rb");
      const long dataSize = cimg::fsize(nfile);
      if (dataSize<=0) {
        cimg::fclose(nfile);
        throw CImgIOException(_cimg_instance
                              "load_jxl(): Failed to get file size '%s'.",
                              cimg_instance,
                              nfilename);
      }
      CImg<ucharT> buffer(dataSize);
      cimg::fread(buffer._data,buffer._width,nfile);
      cimg::fclose(nfile);

View on GitHub (pinned to f788b534b4)

Solutions

  1. Rebuild with cimg_use_jxl defined, linking libjxl (libjxl-dev) and its dependencies
  2. Install libjxl development packages and recompile the native library
  3. Pass a file path instead of FILE* so CImg can dispatch to load_other()
  4. Convert the .jxl image to PNG/JPEG externally and load that

Example fix

// build: -Dcimg_use_jxl=1 -ljxl
// before
img.load_jxl(assetFile); // FILE*, build lacks libjxl
// after
img.load_jxl("/path/to/image.jxl"); // or rebuild with libjxl
Defensive patterns

Strategy: fallback

Validate before calling

#ifndef cimg_use_jxl
  #error "Rebuild with cimg_use_jxl for JPEG XL support"
#endif

Type guard

bool canLoadJxlFromFilePtr() {
#ifdef cimg_use_jxl
  return true;
#else
  return false;
#endif
}

Try / catch

try { img.load_jxl(file, filename); }
catch (CImgIOException&) { img.load("image.png"); // pre-converted fallback
}

Prevention

When it happens

Trigger: Calling load_jxl(std::FILE*) in a build lacking cimg_use_jxl; asset FILE* from Android/uCrop JNI without libjxl linked.

Common situations: Build missing libjxl/highway dependencies; .jxl files handed to a CImg build compiled without JPEG XL support.

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


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