bumptech/glide · error · IllegalArgumentException
Cannot apply transformation on width: {outWidth} or height:
Error message
Cannot apply transformation on width: {outWidth} or height: {outHeight} less than or equal to zero and not Target.SIZE_ORIGINAL What it means
Thrown by BitmapTransformation.transform() when Util.isValidDimensions(outWidth, outHeight) returns false. Glide requires target dimensions to be either positive integers or Target.SIZE_ORIGINAL (Integer.MIN_VALUE). Any other non-positive value is rejected before the transformation runs because it cannot produce a valid Bitmap.
Source
Thrown at library/src/main/java/com/bumptech/glide/load/resource/bitmap/BitmapTransformation.java:72
* Class#getName()} to avoid proguard obfuscation) is an easy way to implement {@link
* #updateDiskCacheKey(java.security.MessageDigest)}} correctly. If additional arguments are
* required they can be passed in to the constructor of the {@code Transformation} and then used to
* update the {@link java.security.MessageDigest} passed in to {@link
* #updateDiskCacheKey(MessageDigest)}. If arguments are primitive types, they can typically easily
* be serialized using {@link java.nio.ByteBuffer}. {@link String} types can be serialized with
* {@link String#getBytes(Charset)} using the constant {@link #CHARSET}.
*
* <p>As with all {@link Transformation}s, all subclasses <em>must</em> implement {@link
* #equals(Object)} and {@link #hashCode()} for memory caching to work correctly.
*/
public abstract class BitmapTransformation implements Transformation<Bitmap> {
@NonNull
@Override
public final Resource<Bitmap> transform(
@NonNull Context context, @NonNull Resource<Bitmap> resource, int outWidth, int outHeight) {
if (!Util.isValidDimensions(outWidth, outHeight)) {
throw new IllegalArgumentException(
"Cannot apply transformation on width: "
+ outWidth
+ " or height: "
+ outHeight
+ " less than or equal to zero and not Target.SIZE_ORIGINAL");
}
BitmapPool bitmapPool = Glide.get(context).getBitmapPool();
Bitmap toTransform = resource.get();
int targetWidth = outWidth == Target.SIZE_ORIGINAL ? toTransform.getWidth() : outWidth;
int targetHeight = outHeight == Target.SIZE_ORIGINAL ? toTransform.getHeight() : outHeight;
Bitmap transformed = transform(bitmapPool, toTransform, targetWidth, targetHeight);
final Resource<Bitmap> result;
if (toTransform.equals(transformed)) {
result = resource;
} else {
result = BitmapResource.obtain(transformed, bitmapPool);
}View on GitHub (pinned to eb14a895d8)
Solutions
- Use Target.SIZE_ORIGINAL instead of -1 or 0 when you want the original size.
- Guard the call site: only call .override(w, h) when w > 0 && h > 0, otherwise omit override() to let Glide use the target dimensions.
- Defer the load until after the target View has been measured (e.g. in onPreDraw listener or after layout).
- If you compute dimensions, validate them and fall back to Target.SIZE_ORIGINAL when invalid.
Example fix
// before
Glide.with(view).load(url).override(view.getWidth(), view.getHeight()).into(view);
// after (guard against 0)
int w = view.getWidth();
int h = view.getHeight();
RequestBuilder<Drawable> req = Glide.with(view).load(url);
if (w > 0 && h > 0) {
req = req.override(w, h);
}
req.into(view); Defensive patterns
Strategy: validation
Validate before calling
// Validate dimensions before calling override() or a transformation.
boolean isValidGlideDimension(int w, int h) {
return (w > 0 && h > 0)
|| w == Target.SIZE_ORIGINAL
|| h == Target.SIZE_ORIGINAL;
}
// Usage:
RequestBuilder<Drawable> req = Glide.with(view).load(url);
if (isValidGlideDimension(w, h)) req = req.override(w, h);
req.into(view); Prevention
- Always treat Target.SIZE_ORIGINAL as the only valid non-positive dimension sentinel.
- Guard override() calls in onResourceReady / target callbacks where dimensions may be 0.
- Defer image loads until the host View has been measured.
When it happens
Trigger: Calling .override(width, height) with 0 or a negative value other than Target.SIZE_ORIGINAL on a request that applies a BitmapTransformation (CenterCrop, RoundedCorners, etc.). Also triggered by a custom Transformation that forwards invalid outWidth/outHeight, or by computed dimensions (e.g. view measured width/height of 0 passed through override().
Common situations: Loading into a View that has not been laid out yet (getWidth()==0) and feeding those dimensions via .override(). Passing -1 as a sentinel instead of Target.SIZE_ORIGINAL. Miscalculating dimensions in a custom target's onResourceReady before calling run() or into().
Related errors
- Cannot scale with factor: {exactScaleFactor} from: {downsamp
- Unable to convert {drawable} to a Bitmap
- MultiTransformation must contain at least one Transformation
- Cannot round with null rounding
- Requested frame must be non-negative, or DEFAULT_FRAME, give
AI-assisted analysis of bumptech/glide@eb14a895d8 (2026-08-14).
Data as JSON: /api/errors/144c1b8beb18ca55.
Report an issue: GitHub.