Yalantis/uCrop · warning

save_pnm(): Instance is volumetric, only the first slice wil

Error message

save_pnm(): Instance is volumetric, only the first slice will be saved in file '%s'.

What it means

Warning from CImg<T>::save_pnm() when the image is volumetric (_depth>1). PNM (PBM/PGM/PPM) formats store a single 2D image, so only the first slice is written and remaining slices are dropped. The save completes without error.

Source

Thrown at ucrop/src/main/jni/CImg.h:62282

      return _save_pnm(0,filename,bytes_per_pixel);
    }

    //! Save image as a PNM file \overloading.
    const CImg<T>& save_pnm(std::FILE *const file, const unsigned int bytes_per_pixel=0) const {
      return _save_pnm(file,0,bytes_per_pixel);
    }

    const CImg<T>& _save_pnm(std::FILE *const file, const char *const filename,
                             const unsigned int bytes_per_pixel=0) const {
      if (!file && !filename)
        throw CImgArgumentException(_cimg_instance
                                    "save_pnm(): Specified filename is (null).",
                                    cimg_instance);
      if (is_empty()) { cimg::fempty(file,filename); return *this; }

      double stmin, stmax = (double)max_min(stmin);
      if (_depth>1)
        cimg::warn(_cimg_instance
                   "save_pnm(): Instance is volumetric, only the first slice will be saved in file '%s'.",
                   cimg_instance,
                   filename?filename:"(FILE*)");
      if (_spectrum>3)
        cimg::warn(_cimg_instance
                   "save_pnm(): Instance is multispectral, only the three first channels will be saved in file '%s'.",
                   cimg_instance,
                   filename?filename:"(FILE*)");
      if (stmin<0 || (bytes_per_pixel==1 && stmax>=256) || stmax>=65536)
        cimg::warn(_cimg_instance
                   "save_pnm(): Instance has pixel values in [%g,%g], probable type overflow in file '%s'.",
                   cimg_instance,
                   stmin,stmax,filename?filename:"(FILE*)");

      std::FILE *const nfile = file?file:cimg::fopen(filename,"wb");
      const T
        *ptr_r = data(0,0,0,0),
        *ptr_g = (_spectrum>=2)?data(0,0,0,1):0,

View on GitHub (pinned to f788b534b4)

Solutions

  1. Save each slice separately: cimg_for_z(img,z) img.get_slice(z).save_pnm(...);
  2. Use a volume-capable format (.cimg, TIFF) instead
  3. Take a single slice explicitly with get_slice(z) if that is intended
  4. Ignore the warning if the first slice suffices

Example fix

// before
volume.save_pnm("out.ppm");
// after
cimg_for_z(volume,z) volume.get_slice(z).save_pnm(cimg::format("out_%d.ppm",z));
Defensive patterns

Strategy: validation

Validate before calling

if (img.depth() > 1) { /* save slices or choose another format */ }

Try / catch

// warning only; guard by depth check before calling save_pnm

Prevention

When it happens

Trigger: Calling save_pnm() (or save_pnm/save_ppm/save_pgm helpers) on an image whose _depth>1.

Common situations: Writing 3D volumes or frame stacks to PPM/PGM, common in coursework or when interoperating with tools that only read 2D PNM.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08). Data as JSON: /api/errors/c35caf5703783c27. Report an issue: GitHub.