wasabeef/glide-transformations · error · IllegalArgumentException
Cannot apply transformation on width
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
Glide's Transformations (jp.wasabeef:glide-transformations) wraps Glide's own contract: the target dimensions passed to transform() must be positive numbers or Target.SIZE_ORIGINAL. The library throws this IllegalArgumentException up front because applying a bitmap transformation to a non-positive target size is undefined and would downstream fail in Glide's BitmapTransformation. It is a fail-fast guard mirroring Glide core's Util.isValidDimensions check.
Solutions
- Ensure the view/size is laid out before loading: load in onLayout, ViewTreeObserver.OnGlobalLayoutListener, or wait for view.getWidth() > 0.
- If you intend original size, pass Target.SIZE_ORIGINAL (which is -1), not 0.
- Remove or fix a RequestOptions.override(w, h) call that passes 0/negative values; use positive pixel dimensions.
- If loading into a GONE view, switch to INVISIBLE or provide explicit .override(width, height) with positive values.
- Wrap transform target sizes: if computed size <= 0, skip the transformation request or clamp to a fallback size like screen dimensions.
Example fix
// before
Glide.with(context)
.load(url)
.apply(RequestOptions.bitmapTransform(new BlurTransformation())
.override(view.getWidth(), view.getHeight())) // 0x0 before layout
.into(imageView);
// after
imageView.post(() -> {
int w = imageView.getWidth() > 0 ? imageView.getWidth() : Target.SIZE_ORIGINAL;
int h = imageView.getHeight() > 0 ? imageView.getHeight() : Target.SIZE_ORIGINAL;
Glide.with(context)
.load(url)
.apply(RequestOptions.bitmapTransform(new BlurTransformation())
.override(w, h))
.into(imageView);
}); Defensive patterns
Strategy: validation
Validate before calling
// Kotlin/Java guard before requesting the transformation
boolean valid = (w == Target.SIZE_ORIGINAL || w > 0) && (h == Target.SIZE_ORIGINAL || h > 0);
if (!valid) {
w = Target.SIZE_ORIGINAL; // or fall back to a measured/default size
h = Target.SIZE_ORIGINAL;
}
RequestOptions opts = RequestOptions.bitmapTransform(new BlurTransformation()).override(w, h); Type guard
// Java
static boolean isValidDimensions(int width, int height) {
return (width == Target.SIZE_ORIGINAL || width > 0)
&& (height == Target.SIZE_ORIGINAL || height > 0);
} Try / catch
// Java
try {
Glide.with(ctx).load(url)
.apply(RequestOptions.bitmapTransform(new BlurTransformation()).override(w, h))
.into(iv);
} catch (IllegalArgumentException e) {
if (e.getMessage() != null && e.getMessage().contains("Cannot apply transformation")) {
Glide.with(ctx).load(url)
.apply(RequestOptions.bitmapTransform(new BlurTransformation()))
.into(iv); // let Glide resolve size itself
} else {
throw e;
}
} Prevention
- Never call override() with values read from a view before it is laid out; use ViewTreeObserver or view.post().
- Use Target.SIZE_ORIGINAL (-1) constant for original size, never 0 or -2.
- For GONE views, use INVISIBLE or explicit positive override dimensions.
- Prefer not calling override() at all and letting Glide compute size from the Target.
- Centralize RequestOptions creation in a helper that validates dimensions before applying transformations.
When it happens
Trigger: Calling Glide RequestBuilder.transform() / apply(RequestOptions.transform()) with override(Target.SIZE_ORIGINAL) replaced by override(0), override(-1), or sizes computed from a zero-sized View (e.g. view.getWidth() before layout returns 0), or from useUnlimitedSourceGeneratorsPool/custom size strategies that resolve to <=0; any RequestOptions whose override dimensions are not Target.SIZE_ORIGINAL (-1) but <= 0.
Common situations: Loading into a View with GONE/zero width or height, applying transformations inside custom Views measured too late (onCreate without ViewTreeObserver), programmatic override(0, 0) defaults, custom Target implementations whose getSize() callback reports 0 before layout, or misuse of Target.SIZE_ORIGINAL constant (passing 0 instead of -1).
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
AI-assisted analysis of wasabeef/glide-transformations@d950f0c33f (2026-09-10).
Data as JSON: /api/errors/27160a64bb939738.
Report an issue: GitHub.
Appendix: source
Thrown at transformations/src/main/java/jp/wasabeef/glide/transformations/BitmapTransformation.java:42
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.Transformation;
import com.bumptech.glide.load.engine.Resource;
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapResource;
import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.util.Util;
import java.security.MessageDigest;
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(context.getApplicationContext(), bitmapPool, toTransform, targetWidth, targetHeight);
final Resource<Bitmap> result;
if (toTransform.equals(transformed)) {
result = resource;
} else {
result = BitmapResource.obtain(transformed, bitmapPool);
}
return result;
}
View on GitHub (pinned to d950f0c33f)