Yalantis/uCrop · error · CImgArgumentException
resize(): Invalid specified interpolation %d (should be { -1
Error message
resize(): Invalid specified interpolation %d (should be { -1=raw | 0=none | 1=nearest | 2=average | 3=linear | 4=grid | 5=cubic | 6=lanczos }). What it means
CImg's resize() accepts an interpolation_type parameter restricted to values -1 (raw), 0 (none), 1 (nearest), 2 (average), 3 (linear), 4 (grid), 5 (cubic), 6 (lanczos). When the switch in the resize implementation falls through to the default branch, it means the caller passed an integer outside this set, so CImg throws a CImgArgumentException naming the offending value. The library fails fast instead of silently substituting an interpolation method.
Source
Thrown at ucrop/src/main/jni/CImg.h:38761
val4 = ptrs<ptrsmax?(double)*(ptrs + 2*sxyz):val3,
val = (val0*w0 + val1*w1 + val2*w2 + val3*w3 + val4*w4)/(w1 + w2 + w3 + w4);
*ptrd = (T)(val<vmin?vmin:val>vmax?vmax:val);
ptrd+=sxyz;
ptrs+=*(poff++);
}
}
}
}
resz.assign();
} else resc.assign(resz,true);
return resc._is_shared?(resz._is_shared?(resy._is_shared?(resx._is_shared?(+(*this)):resx):resy):resz):resc;
} break;
// Unknown interpolation.
//
default :
throw CImgArgumentException(_cimg_instance
"resize(): Invalid specified interpolation %d "
"(should be { -1=raw | 0=none | 1=nearest | 2=average | 3=linear | 4=grid | "
"5=cubic | 6=lanczos }).",
cimg_instance,
interpolation_type);
}
return res;
}
//! Resize image to dimensions of another image.
/**
\param src Reference image used for dimensions.
\param interpolation_type Interpolation method.
\param boundary_conditions Boundary conditions.
Can be { 0=dirichlet | 1=neumann | 2=periodic | 3=mirror }.
\param centering_x Set centering type (only if \p interpolation_type=0).
\param centering_y Set centering type (only if \p interpolation_type=0).
\param centering_z Set centering type (only if \p interpolation_type=0).View on GitHub (pinned to f788b534b4)
Solutions
- Set interpolation_type to one of the documented values: -1, 0, 1, 2, 3, 4, 5, or 6 (e.g. 3 for linear, 6 for lanczos).
- If your code uses its own enum, add an explicit mapping from your enum to CImg's constants before calling resize().
- Check for uninitialized or corrupted interpolation_type values at the call site (log/print the value shown in the message).
- If you intentionally want no interpolation, pass 0 (none) rather than an out-of-range sentinel.
Example fix
// before img.resize(w, h, -100, -100, -100, 2, 7); // 7 is invalid // after img.resize(w, h, -100, -100, -100, 2, 6); // 6 = lanczos (valid range -1..6)
Defensive patterns
Strategy: validation
Validate before calling
// C++
bool isValidInterpolation(int t) {
return t >= -1 && t <= 6; // -1 raw,0 none,1 nearest,2 average,3 linear,4 grid,5 cubic,6 lanczos
}
if (!isValidInterpolation(interp)) throw std::invalid_argument("interpolation must be in [-1,6]");
img.resize(w, h, -100, -100, -100, 2, interp); Type guard
bool isValidInterpolation(int t) { return t >= -1 && t <= 6; } Try / catch
try {
img.resize(w, h, -100, -100, -100, 2, interp);
} catch (const cimg_library::CImgArgumentException& e) {
// log e.what(), fall back to a safe default
img.resize(w, h, -100, -100, -100, 2, 3); // linear
} Prevention
- Use CImg's named constants / a wrapper enum restricted to -1..6 instead of raw ints
- Validate any user- or config-supplied quality setting against the allowed set before mapping to interpolation_type
- Never forward your own enum values directly to resize(); add an explicit mapping
- Initialize the interpolation variable at declaration to avoid garbage values
When it happens
Trigger: Calling CImg<T>::resize() (or get_resize()) with interpolation_type not in {-1,0,1,2,3,4,5,6}, e.g. passing 7, a negative sentinel other than -1, or an uninitialized/garbage int. Also happens when a caller maps its own enum (whose values don't line up with CImg's) directly into the parameter.
Common situations: Wrapping CImg in higher-level code where an app-level quality enum (e.g. 0=low,1=medium,2=high) is forwarded verbatim as interpolation_type; a refactor or version change shifting CImg's enum values (e.g. code written for a different lib whose 'lanczos' is 5 vs CImg's 6); passing a bool/flag by mistake; uninitialized variable.
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
- linear_atX(): Empty instance.
- linear_atX_p(): Empty instance.
- linear_atXY(): Empty instance.
- linear_atXY_p(): Empty instance.
- CImg<%s>::%s() [%u]: cubic_atX(): Empty instance.
AI-assisted analysis of Yalantis/uCrop@f788b534b4 (2026-09-08).
Data as JSON: /api/errors/b15abd8af1e54323.
Report an issue: GitHub.