{"record":{"id":"2d40b082fb444d6a","repo":"Yalantis/uCrop","slug":"save-other-file-s-saving-a-volumetric-image-2d40b0","errorCode":null,"errorMessage":"save_other(): File '%s', saving a volumetric image with an external call to ImageMagick only writes the first image slice.","messagePattern":"save_other\\(\\): File '(.+?)', saving a volumetric image with an external call to ImageMagick only writes the first image slice\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"ucrop/src/main/jni/CImg.h","lineNumber":63776,"sourceCode":"      return *this;\n    }\n\n    //! Save image using ImageMagick'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 convert, an external executable binary provided by\n       <a href=\"http://www.imagemagick.org\">ImageMagick</a>.\n       It must be installed for the method to succeed.\n    **/\n    const CImg<T>& save_imagemagick_external(const char *const filename, const unsigned int quality=100) const {\n      if (!filename)\n        throw CImgArgumentException(_cimg_instance\n                                    \"save_imagemagick_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                   \"ImageMagick only writes the first image slice.\",\n                   cimg_instance,filename);\n#ifdef cimg_use_png\n#define _cimg_sie_extension1 \"png\"\n#define _cimg_sie_extension2 \"png\"\n#else\n#define _cimg_sie_extension1 \"pgm\"\n#define _cimg_sie_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\",cimg::temporary_path(),\n                      cimg_file_separator,cimg::filenamerand(),_spectrum==1?_cimg_sie_extension1:_cimg_sie_extension2);\n      } while (cimg::path_exists(filename_tmp));\n#ifdef cimg_use_png\n      save_png(filename_tmp);\n#else","sourceCodeStart":63758,"sourceCodeEnd":63794,"githubUrl":"https://github.com/Yalantis/uCrop/blob/f788b534b48c144edf786c8cddbf0e029e637804/ucrop/src/main/jni/CImg.h#L63758-L63794","documentation":"Same family as the GraphicsMagick variant: when save_other() delegates to an external ImageMagick process (save_imagemagick_external), a volumetric image (_depth>1) is flattened to the first slice because the temp file handed to the 'convert' binary contains only slice 0. CImg warns and continues; deeper slices are lost.","triggerScenarios":"Calling save_other()/save_imagemagick_external() with _depth>1 and no native codec compiled (no cimg_use_png/cimg_use_jpeg), so CImg invokes the ImageMagick 'convert' command.","commonSituations":"Minimal Linux builds lacking libpng/libjpeg so external ImageMagick is used; saving z-stacks to PNG/JPEG; choosing formats not natively compiled into CImg.","solutions":["Rebuild with native codec macros (cimg_use_png, cimg_use_jpeg, cimg_use_tiff) to avoid the external path","Write each slice separately: img.get_slice(z).save_* per z","Use save_cimg() or a volumetric format (TIFF) for 3D data"],"exampleFix":"// before\nvolume.save_other(\"out.jpg\");       // external convert, only slice 0\n// after\nfor (int z = 0; z < volume.depth(); ++z)\n  volume.get_slice(z).save_jpeg(cimg::format(\"out_%03d.jpg\", 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.jpg\", z));\nelse\n  img.save(\"out.jpg\");","typeGuard":"bool is_2d(const cimg_library::CImg<T>& img) { return img.depth() == 1; }","tryCatchPattern":"try { img.save(\"out.jpg\"); } catch (CImgException& e) { /* handle */ }","preventionTips":["Compile with cimg_use_jpeg/cimg_use_png so native codecs bypass ImageMagick","Split volumes into per-slice files","For 3D data use save_cimg() or multi-page TIFF"],"tags":["cimg","imagemagick","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"}