Yalantis/uCrop · error · CImgArgumentException

mirror(): Invalid specified axis '%c'.

Error message

mirror(): Invalid specified axis '%c'.

What it means

CImg's mirror() takes an axis selector that must be one of 'x', 'y', 'z' or 'c'; the internal switch handles only those cases. Any other character reaches the default branch, which throws CImgArgumentException reporting the offending character. The library requires an exact single-character axis identifier.

Source

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

          }
          pf+=(ulongT)_width*_height*(_depth - depth2);
          pb+=(ulongT)_width*_height*(_depth + depth2);
        }
      } break;
      case 'c' : {
        buf = new T[(ulongT)_width*_height*_depth];
        pf = _data; pb = data(0,0,0,_spectrum - 1);
        const unsigned int _spectrum2 = _spectrum/2;
        for (unsigned int v = 0; v<_spectrum2; ++v) {
          std::memcpy(buf,pf,_width*_height*_depth*sizeof(T));
          std::memcpy(pf,pb,_width*_height*_depth*sizeof(T));
          std::memcpy(pb,buf,_width*_height*_depth*sizeof(T));
          pf+=(ulongT)_width*_height*_depth;
          pb-=(ulongT)_width*_height*_depth;
        }
      } break;
      default :
        throw CImgArgumentException(_cimg_instance
                                    "mirror(): Invalid specified axis '%c'.",
                                    cimg_instance,
                                    axis);
      }
      delete[] buf;
      return *this;
    }

    //! Mirror image content along specified axis \newinstance.
    CImg<T> get_mirror(const char axis) const {
      return (+*this).mirror(axis);
    }

    //! Mirror image content along specified axes.
    /**
       \param axes Mirror axes, as a C-string.
       \note \c axes may contains multiple characters, e.g. \c "xyz"
    **/

View on GitHub (pinned to f788b534b4)

Solutions

  1. Pass exactly one of 'x', 'y', 'z', or 'c' (lowercase) to mirror().
  2. If your input is uppercase or a word like 'horizontal', normalize it: map to lowercase and translate words to the corresponding axis character before calling.
  3. Validate the axis character at the call boundary and reject/normalize invalid values with a clear app-level message.
  4. If you need a flip along a different axis, ensure the image actually has that dimension (e.g. 'z' on a 2D image is also not handled — use 'x' or 'y').

Example fix

// before
img.mirror('X'); // invalid: wrong case
// after
img.mirror('x'); // lowercase axis chars only
Defensive patterns

Strategy: validation

Validate before calling

// C++
bool isValidAxis(char axis) { return axis=='x' || axis=='y' || axis=='z' || axis=='c'; }
char axis = std::tolower(userAxis);
if (!isValidAxis(axis)) throw std::invalid_argument("axis must be x, y, z, or c");
img.mirror(axis);

Type guard

bool isValidAxis(char c) { return c=='x'||c=='y'||c=='z'||c=='c'; }

Try / catch

try {
    img.mirror(axis);
} catch (const cimg_library::CImgArgumentException& e) {
    // log and default to a sensible axis
    img.mirror('x');
}

Prevention

When it happens

Trigger: Calling CImg<T>::mirror(axis) with a character other than 'x', 'y', 'z', or 'c' — e.g. 'X' or 'Y' (wrong case), 'horizontal'/'vertical' strings converted wrongly, '0'/'1', a null byte, or a truncated two-character code like 'xy'.

Common situations: Mapping user-facing 'flip horizontal/vertical' options to axis chars with wrong-case output ('X' instead of 'x'); porting code from another library that uses 0/1 axis indices; config files supplying axis names with trailing whitespace or newline characters.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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