{"record":{"id":"ee6c66cc028afa18","repo":"Yalantis/uCrop","slug":"save-cimg-unable-to-save-compressed-data-in-fil","errorCode":null,"errorMessage":"save_cimg(): Unable to save compressed data in file '%s' unless zlib is enabled, saving them uncompressed.","messagePattern":"save_cimg\\(\\): Unable to save compressed data in file '(.+?)' unless zlib is enabled, saving them uncompressed\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":68153,"sourceCode":"    }\n\n    //! Save list into a .cimg file.\n    /**\n       \\param filename Filename to write data to.\n       \\param is_compressed Tells if data compression must be enabled.\n    **/\n    const CImgList<T>& save_cimg(const char *const filename, const bool is_compressed=false) const {\n      return _save_cimg(0,filename,is_compressed);\n    }\n\n    const CImgList<T>& _save_cimg(std::FILE *const file, const char *const filename, const bool is_compressed) const {\n      if (!file && !filename)\n        throw CImgArgumentException(_cimglist_instance\n                                    \"save_cimg(): Specified filename is (null).\",\n                                    cimglist_instance);\n#ifndef cimg_use_zlib\n      if (is_compressed)\n        cimg::warn(_cimglist_instance\n                   \"save_cimg(): Unable to save compressed data in file '%s' unless zlib is enabled, \"\n                   \"saving them uncompressed.\",\n                   cimglist_instance,\n                   filename?filename:\"(FILE*)\");\n#endif\n      const char *const ptype = pixel_type(), *const etype = cimg::endianness()?\"big\":\"little\";\n      std::FILE *const nfile = file?file:cimg::fopen(filename,\"wb\");\n      const bool is_bool = ptype==cimg::type<bool>::string();\n      std::fprintf(nfile,\"%u %s %s_endian\\n\",_width,ptype,etype);\n\n      cimglist_for(*this,l) {\n        const CImg<T>& img = _data[l];\n        std::fprintf(nfile,\"%u %u %u %u\",img._width,img._height,img._depth,img._spectrum);\n        if (img._data) {\n          CImg<T> tmp;\n          if (cimg::endianness()) { tmp = img; cimg::invert_endianness(tmp._data,tmp.size()); }\n          const CImg<T>& ref = cimg::endianness()?tmp:img;\n          bool failed_to_compress = true;","sourceCodeStart":68135,"sourceCodeEnd":68171,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L68135-L68171","documentation":"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.","triggerScenarios":"Calling save_cimg(filename, ..., is_compressed=true) (or saving with a .cimgz filename requesting compression) in a build without cimg_use_zlib.","commonSituations":"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.","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"],"exampleFix":"// before\nimages.save_cimg(\"out.cimgz\", true); // warns without zlib\n// after\n#ifdef cimg_use_zlib\nimages.save_cimg(\"out.cimgz\", true);\n#else\nimages.save_cimg(\"out.cimg\", false);\n#endif","handlingStrategy":"fallback","validationCode":"#ifdef cimg_use_zlib\nimages.save_cimg(\"out.cimgz\", true);\n#else\nimages.save_cimg(\"out.cimg\", false);\n#endif","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["cimg","zlib","compression"],"backgroundTag":"feature-not-enabled","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"}