Yalantis/uCrop · warning
save_cimg(): Unable to save compressed data in file '%s' unl
Error message
save_cimg(): Unable to save compressed data in file '%s' unless zlib is enabled, saving them uncompressed.
What it means
CImgList<T>::save_cimg() with is_compressed set warns when the library was built without zlib (cimg_use_zlib undefined): compressed .cimgz output cannot be produced, so the data is written uncompressed instead. The file is still saved, but larger and with a different layout than a genuinely compressed .cimgz.
Source
Thrown at ucrop/src/main/jni/CImg.h:68153
}
//! Save list into a .cimg file.
/**
\param filename Filename to write data to.
\param is_compressed Tells if data compression must be enabled.
**/
const CImgList<T>& save_cimg(const char *const filename, const bool is_compressed=false) const {
return _save_cimg(0,filename,is_compressed);
}
const CImgList<T>& _save_cimg(std::FILE *const file, const char *const filename, const bool is_compressed) const {
if (!file && !filename)
throw CImgArgumentException(_cimglist_instance
"save_cimg(): Specified filename is (null).",
cimglist_instance);
#ifndef cimg_use_zlib
if (is_compressed)
cimg::warn(_cimglist_instance
"save_cimg(): Unable to save compressed data in file '%s' unless zlib is enabled, "
"saving them uncompressed.",
cimglist_instance,
filename?filename:"(FILE*)");
#endif
const char *const ptype = pixel_type(), *const etype = cimg::endianness()?"big":"little";
std::FILE *const nfile = file?file:cimg::fopen(filename,"wb");
const bool is_bool = ptype==cimg::type<bool>::string();
std::fprintf(nfile,"%u %s %s_endian\n",_width,ptype,etype);
cimglist_for(*this,l) {
const CImg<T>& img = _data[l];
std::fprintf(nfile,"%u %u %u %u",img._width,img._height,img._depth,img._spectrum);
if (img._data) {
CImg<T> tmp;
if (cimg::endianness()) { tmp = img; cimg::invert_endianness(tmp._data,tmp.size()); }
const CImg<T>& ref = cimg::endianness()?tmp:img;
bool failed_to_compress = true;View on GitHub (pinned to f788b534b4)
Solutions
- Recompile defining cimg_use_zlib and link zlib (-lz, install zlib dev package)
- Save uncompressed: pass is_compressed=false or use the .cimg extension
- Read back accordingly — a file saved this way is uncompressed despite any .cimgz naming
Example fix
// before
images.save_cimg("out.cimgz", true); // warns without zlib
// after
#ifdef cimg_use_zlib
images.save_cimg("out.cimgz", true);
#else
images.save_cimg("out.cimg", false);
#endif Defensive patterns
Strategy: fallback
Validate before calling
#ifdef cimg_use_zlib
images.save_cimg("out.cimgz", true);
#else
images.save_cimg("out.cimg", false);
#endif Prevention
- Define cimg_use_zlib and link zlib when compression is needed
- Match file extension (.cimg vs .cimgz) to actual compression
- Never assume .cimgz content is compressed on non-zlib builds
When it happens
Trigger: Calling save_cimg(filename, ..., is_compressed=true) (or saving with a .cimgz filename requesting compression) in a build without cimg_use_zlib.
Common situations: Default header-only CImg builds without zlib linked; porting code that used a zlib-enabled build to one without; toolchains missing zlib dev headers so cimg_use_zlib was never defined.
Related errors
- load_cimg(): Unable to load compressed data from file '%s' u
- save_cimg(): Failed to save compressed data for file '%s', s
- get_serialize(): Failed to save compressed data, saving them
- load_bmp(): Unable to load compressed data from '(*FILE)' in
- save_jxl(): Failed to set lossy compression level when savin
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/ee6c66cc028afa18.
Report an issue: GitHub.