Yalantis/uCrop · warning
save_cimg(): Failed to save compressed data for file '%s', s
Error message
save_cimg(): Failed to save compressed data for file '%s', saving them uncompressed.
What it means
During save_cimg() of compressed data (zlib enabled), the deflate compression of a tile/strip failed (failed_to_compress set). The library warns and writes the data uncompressed for that item instead, so the save still completes.
Source
Thrown at ucrop/src/main/jni/CImg.h:68199
cbuf = new Bytef[csiz];
failed_to_compress = (bool)compress(cbuf,&csiz,(Bytef*)buf,siz);
if (!failed_to_compress) {
std::fprintf(nfile," #%lu\n",csiz);
cimg::fwrite(cbuf,csiz,nfile);
}
delete[] buf;
} else { // Non-boolean data
const ulongT siz = sizeof(T)*ref.size();
csiz = siz + siz/100 + 16;
cbuf = new Bytef[csiz];
failed_to_compress = (bool)compress(cbuf,&csiz,(Bytef*)ref._data,siz);
if (!failed_to_compress) {
std::fprintf(nfile," #%lu\n",csiz);
cimg::fwrite(cbuf,csiz,nfile);
}
}
if (failed_to_compress)
cimg::warn(_cimglist_instance
"save_cimg(): Failed to save compressed data for file '%s', saving them uncompressed.",
cimglist_instance,
filename?filename:"(FILE*)");
delete[] cbuf;
#endif
}
if (failed_to_compress) { // Write non-compressed
std::fputc('\n',nfile);
if (is_bool) { // Boolean data (bitwise)
ulongT siz;
const unsigned char *const buf = ref._bool2uchar(siz,false);
cimg::fwrite(buf,siz,nfile);
delete[] buf;
} else cimg::fwrite(ref._data,ref.size(),nfile); // Non-boolean data
}
} else std::fputc('\n',nfile);
}
if (!file) cimg::fclose(nfile);View on GitHub (pinned to f788b534b4)
Solutions
- Check available memory; compress smaller images or reduce resolution before saving
- Verify the zlib library is correctly built/linked (zlibVersion() sanity check)
- Save uncompressed (is_compressed=false) if compression keeps failing
- Free other allocations before saving to avoid compress() failing on allocation
Example fix
// before
images.save_cimg("out.cimgz", true);
// after
try {
images.save_cimg("out.cimgz", true);
} catch (...) { /* may have fallen back to uncompressed */ }
// or avoid compression entirely:
images.save_cimg("out.cimg", false); Defensive patterns
Strategy: fallback
Validate before calling
// preflight zlib
if (zlibVersion() == nullptr) { /* zlib broken: save uncompressed */ images.save_cimg("out.cimg", false); } Prevention
- Ensure adequate memory for compression buffers
- Sanity-check zlib linkage (zlibVersion) at startup
- Fall back to uncompressed saving when compression is unreliable
When it happens
Trigger: cimg_use_zlob... i.e. zlib-enabled build where compress()/deflate returns Z_* error — typically out-of-memory for the compression buffer, or zlib returning an error on very large buffers; internal buffer allocation failure for cbuf.
Common situations: Very large images exhausting memory during compression; corrupted/limited zlib installation; resource-constrained embedded environments (Android NDK builds of uCrop).
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- get_serialize(): Failed to save compressed data, saving them
- load_cimg(): Unable to load compressed data from file '%s' u
- save_cimg(): Unable to save compressed data in file '%s' unl
- CImg<%s>::safe_size(): Specified size (%u,%u,%u,%u) exceeds
- CImg<%s>::safe_size(): Specified size (%u,%u,%u,%u) overflow
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/0761cc3b52a5d026.
Report an issue: GitHub.