load fails due to fitCenter computing zero-dimension bitmap size
- Dominant language
- Java
- Stars
- 35k
- Forks
- 6.2k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 8
Description
**Glide Version**: 4.8.0
**Issue details / Repro steps / Use case background**:
I load image 5x900 pixels into view with size 238x178.
`TransformationUtils.fitCenter` got to situation where `minPercentage` was 0.19
then this code computed zero-width image size:
```
int targetWidth = Math.round(minPercentage * inBitmap.getWidth());
int targetHeight = Math.round(minPercentage * inBitmap.getHeight());
```
and this leads to load error due to failure in log as seen below
I suggest that above computations always produce Math.max(1, ...) so that rounding to zero never happens.
**Glide load line / `GlideModule` (if any) / list Adapter code (if any)**:
```kotlin
GlideApp.with(act).asDrawable()
.optionalFitCenter()
.load(this).into(v)
```
**Stack trace / LogCat**:
```ruby
java.lang.IllegalArgumentException: width and height must be > 0
at android.graphics.Bitmap.createBitmap(Bitmap.java:1061)
at android.graphics.Bitmap.createBitmap(Bitmap.java:1040)
at android.graphics.Bitmap.createBitmap(Bitmap.java:1007)
at com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool.createBitmap(LruBitmapPool.java:149)
at com.bumptech.glide.load.engine.bitmap_recycle.LruBitmapPool.get(LruBitmapPool.java:131)
at com.bumptech.glide.load.resource.bitmap.TransformationUtils.fitCenter(TransformationUtils.java:191)
at com.bumptech.glide.load.resource.bitmap.FitCenter.transform(FitCenter.java:20)
at com.bumptech.glide.load.resource.bitmap.BitmapTransformation.transform(BitmapTransformation.java:81)
at com.bumptech.glide.load.engine.DecodeJob.onResourceDecoded(DecodeJob.java:540)
at com.bumptech.glide.load.engine.DecodeJob$DecodeCallback.onResourceDecoded(DecodeJob.java:604)
at com.bumptech.glide.load.engine.DecodePath.decode(DecodePath.java:46)
at com.bumptech.glide.load.engine.LoadPath.loadWithExceptionList(LoadPath.java:58)
at com.bumptech.glide.load.engine.LoadPath.load(LoadPath.java:43)
at com.bumptech.glide.load.engine.DecodeJob.runLoadPath(DecodeJob.java:507)
at com.bumptech.glide.load.engine.DecodeJob.decodeFromFetcher(DecodeJob.java:472)
at com.bumptech.glide.load.engine.DecodeJob.decodeFromData(DecodeJob.java:458)
at com.bumptech.glide.load.engine.DecodeJob.decodeFromRetrievedData(DecodeJob.java:410)
at com.bumptech.glide.load.engine.DecodeJob.onDataFetcherReady(DecodeJob.java:379)
at com.bumptech.glide.load.engine.SourceGenerator.onDataReady(SourceGenerator.java:112)
```
Image that I try to load. You can test even with greater extremes such as 1x10000 pixels, they fail too.

Contributor guide
Assessment
This issue has not been assessed yet.