{"record":{"id":"f1e0f4573d0acbf7","repo":"Yalantis/uCrop","slug":"save-other-file-s-saving-a-volumetric-image","errorCode":null,"errorMessage":"save_other(): File '%s', saving a volumetric image with an external call to GraphicsMagick only writes the first image slice.","messagePattern":"save_other\\(\\): File '(.+?)', saving a volumetric image with an external call to GraphicsMagick only writes the first image slice\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":63718,"sourceCode":"      return *this;\n    }\n\n    //! Save image using GraphicsMagick's external binary.\n    /**\n       \\param filename Filename, as a C-string.\n       \\param quality Image quality (expressed in percent), when the file format supports it.\n       \\note This method uses \\c gm, an external executable binary provided by\n         <a href=\"http://www.graphicsmagick.org\">GraphicsMagick</a>.\n       It must be installed for the method to succeed.\n    **/\n    const CImg<T>& save_graphicsmagick_external(const char *const filename, const unsigned int quality=100) const {\n      if (!filename)\n        throw CImgArgumentException(_cimg_instance\n                                    \"save_graphicsmagick_external(): Specified filename is (null).\",\n                                    cimg_instance);\n      if (is_empty()) { cimg::fempty(0,filename); return *this; }\n      if (_depth>1)\n        cimg::warn(_cimg_instance\n                   \"save_other(): File '%s', saving a volumetric image with an external call to \"\n                   \"GraphicsMagick only writes the first image slice.\",\n                   cimg_instance,filename);\n\n#ifdef cimg_use_png\n#define _cimg_sge_extension1 \"png\"\n#define _cimg_sge_extension2 \"png\"\n#else\n#define _cimg_sge_extension1 \"pgm\"\n#define _cimg_sge_extension2 \"ppm\"\n#endif\n      CImg<charT> command(1024), filename_tmp(256);\n      do {\n        cimg_snprintf(filename_tmp,filename_tmp._width,\"%s%c%s.%s\",\n                      cimg::temporary_path(),cimg_file_separator,cimg::filenamerand(),\n                      _spectrum==1?_cimg_sge_extension1:_cimg_sge_extension2);\n      } while (cimg::path_exists(filename_tmp));\n","sourceCodeStart":63700,"sourceCodeEnd":63736,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L63700-L63736","documentation":"When saving via an external GraphicsMagick process (save_graphicsmagick_external, called from save_other), CImg warns that volumetric images (_depth>1) are truncated to the first slice because the external command-line tool receives a temporary flat image file. Non-fatal; slices beyond z=0 are lost silently after the warning.","triggerScenarios":"Calling save_other()/save_graphicsmagick_external() with _depth>1 when no native codec is compiled in for the target format (no cimg_use_png etc.), so CImg shells out to the 'gm convert' binary.","commonSituations":"Build without cimg_use_* flags forcing external-tool fallbacks; saving 3D data to PNG/JPEG via GraphicsMagick; CI/Docker images lacking native codec libraries.","solutions":["Compile CImg with the native codec macro for the target format (e.g. cimg_use_png, cimg_use_jpeg) so save_other uses the in-process codec","Save slices individually before delegating to the external tool","Use save_cimg() (native CImg format) for volumetric data","Install GraphicsMagick with multi-page support and switch to formats like TIFF/MIFF if volume support is needed"],"exampleFix":"// before\nvolume.save_other(\"out.png\");       // external gm, only slice 0\n// after\nfor (int z = 0; z < volume.depth(); ++z)\n  volume.get_slice(z).save_png(cimg::format(\"out_%03d.png\", z));","handlingStrategy":"validation","validationCode":"if (img.depth() > 1)\n  for (int z = 0; z < img.depth(); ++z) img.get_slice(z).save(cimg::format(\"out_%03d.png\", z));\nelse\n  img.save(\"out.png\");","typeGuard":"bool is_2d(const cimg_library::CImg<T>& img) { return img.depth() == 1; }","tryCatchPattern":"try { img.save(\"out.png\"); } catch (CImgException& e) { /* handle */ }","preventionTips":["Build CImg with native codec macros (cimg_use_png, cimg_use_tiff) to avoid external-tool fallbacks","Slice volumetric data before external-tool saves","Check whether gm/convert binaries are being used (verbose logs) in production"],"tags":["cimg","graphicsmagick","external-tool","volumetric","data-loss"],"backgroundTag":"unsupported-operation","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"}