{"record":{"id":"27160a64bb939738","repo":"wasabeef/glide-transformations","slug":"cannot-apply-transformation-on-width-outwidth","errorCode":null,"errorMessage":"Cannot apply transformation on width: ${outWidth} or height: ${outHeight} less than or equal to zero and not Target.SIZE_ORIGINAL","messagePattern":"Cannot apply transformation on width: (.+?) or height: (.+?) less than or equal to zero and not Target\\.SIZE_ORIGINAL","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"transformations/src/main/java/jp/wasabeef/glide/transformations/BitmapTransformation.java","lineNumber":42,"sourceCode":"\nimport com.bumptech.glide.Glide;\nimport com.bumptech.glide.load.Transformation;\nimport com.bumptech.glide.load.engine.Resource;\nimport com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;\nimport com.bumptech.glide.load.resource.bitmap.BitmapResource;\nimport com.bumptech.glide.request.target.Target;\nimport com.bumptech.glide.util.Util;\n\nimport java.security.MessageDigest;\n\npublic abstract class BitmapTransformation implements Transformation<Bitmap> {\n\n  @NonNull\n  @Override\n  public final Resource<Bitmap> transform(@NonNull Context context, @NonNull Resource<Bitmap> resource,\n                                          int outWidth, int outHeight) {\n    if (!Util.isValidDimensions(outWidth, outHeight)) {\n      throw new IllegalArgumentException(\n        \"Cannot apply transformation on width: \" + outWidth + \" or height: \" + outHeight\n          + \" less than or equal to zero and not Target.SIZE_ORIGINAL\");\n    }\n    BitmapPool bitmapPool = Glide.get(context).getBitmapPool();\n    Bitmap toTransform = resource.get();\n    int targetWidth = outWidth == Target.SIZE_ORIGINAL ? toTransform.getWidth() : outWidth;\n    int targetHeight = outHeight == Target.SIZE_ORIGINAL ? toTransform.getHeight() : outHeight;\n    Bitmap transformed = transform(context.getApplicationContext(), bitmapPool, toTransform, targetWidth, targetHeight);\n\n    final Resource<Bitmap> result;\n    if (toTransform.equals(transformed)) {\n      result = resource;\n    } else {\n      result = BitmapResource.obtain(transformed, bitmapPool);\n    }\n    return result;\n  }\n","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/wasabeef/glide-transformations/blob/d950f0c33f27f864e4ab4b26fce66c27079911c1/transformations/src/main/java/jp/wasabeef/glide/transformations/BitmapTransformation.java#L24-L60","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","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."],"exampleFix":"// before\nGlide.with(context)\n    .load(url)\n    .apply(RequestOptions.bitmapTransform(new BlurTransformation())\n        .override(view.getWidth(), view.getHeight())) // 0x0 before layout\n    .into(imageView);\n\n// after\nimageView.post(() -> {\n  int w = imageView.getWidth() > 0 ? imageView.getWidth() : Target.SIZE_ORIGINAL;\n  int h = imageView.getHeight() > 0 ? imageView.getHeight() : Target.SIZE_ORIGINAL;\n  Glide.with(context)\n      .load(url)\n      .apply(RequestOptions.bitmapTransform(new BlurTransformation())\n          .override(w, h))\n      .into(imageView);\n});","handlingStrategy":"validation","validationCode":"// Kotlin/Java guard before requesting the transformation\nboolean valid = (w == Target.SIZE_ORIGINAL || w > 0) && (h == Target.SIZE_ORIGINAL || h > 0);\nif (!valid) {\n    w = Target.SIZE_ORIGINAL; // or fall back to a measured/default size\n    h = Target.SIZE_ORIGINAL;\n}\nRequestOptions opts = RequestOptions.bitmapTransform(new BlurTransformation()).override(w, h);","typeGuard":"// Java\nstatic boolean isValidDimensions(int width, int height) {\n    return (width == Target.SIZE_ORIGINAL || width > 0)\n        && (height == Target.SIZE_ORIGINAL || height > 0);\n}","tryCatchPattern":"// Java\ntry {\n    Glide.with(ctx).load(url)\n        .apply(RequestOptions.bitmapTransform(new BlurTransformation()).override(w, h))\n        .into(iv);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"Cannot apply transformation\")) {\n        Glide.with(ctx).load(url)\n            .apply(RequestOptions.bitmapTransform(new BlurTransformation()))\n            .into(iv); // let Glide resolve size itself\n    } else {\n        throw e;\n    }\n}","preventionTips":["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."],"tags":["android","glide","bitmap-transformation","illegal-argument","image-loading"],"backgroundTag":"invalid-argument-value","analyzedSha":"d950f0c33f27f864e4ab4b26fce66c27079911c1","analyzedAt":"2026-09-10T09:57:42.658Z","contentChangedAt":"2026-09-10T09:57:42.658Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}