Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can not resize correctly #3673

Closed
mrtry opened this issue May 29, 2019 · 5 comments · Fixed by #3689
Closed

Can not resize correctly #3673

mrtry opened this issue May 29, 2019 · 5 comments · Fixed by #3689
Labels

Comments

@mrtry
Copy link

mrtry commented May 29, 2019

Glide Version: 4.5.0

Issue details / Repro steps / Use case background:

I was trying to resize an image like the one below.

  • 4032x3024
  • ORIENTATION_ROTATE_90

Tried the following code.

GlideApp.with(context)
        .asBitmap()
        .override(1977, 2636) // consider the orientation
        .load(uri)
        .submit()
        .get()

I wanted an image 1977x2636.
However, I got an image 2636x3515.

Below is the Downsampler's log.

V/Downsampler: Calculate scaling, source: [4032x3024], target: [1977x2636], power of two scaled: [4032x3024], exact scale factor: 0.65376985, power of 2 sample size: 1, adjusted scale factor: 0.8716931343078613, target density: 1631763243, density: 1871946751
V/Downsampler: Calculated target [3515x2636] for source [4032x3024], sampleSize: 1, targetDensity: 1631763243, density: 1871946751, density multiplier: 0.8716932
V/Downsampler: Decoded [3515x2636] ARGB_8888 (37062160) from [4032x3024] image/jpeg with inBitmap [3515x2636] ARGB_8888 (37062160) for [1977x2636], sample size: 1, density: 1871946751, target density: 1631763243, thread: glide-source-thread-0, duration: 287.763101

Examined the calculation of exact scale factor and adjusted scale factor of Calculate scaling.

exact scale factor consider the orientation.
see: Downsampler.java#L346-L356

However, adjusted scale factor does not consider the orientation.
see: Downsampler.java#L440-L441

I think that this is why can not resize correctly.
Is the calculation of the adjusted scale factor correct, or a bug?

@mrtry
Copy link
Author

mrtry commented May 29, 2019

By using .override(2636, 1977), we were able to obtain the intended image.

@sjudd
Copy link
Collaborator

sjudd commented May 31, 2019

What version of Android were you using?

@sjudd sjudd added the bug label May 31, 2019
@sjudd
Copy link
Collaborator

sjudd commented May 31, 2019

Actually this definitely looks like a bug, nice catch, thanks for reporting.

sjudd added a commit to sjudd/glide that referenced this issue Jun 1, 2019
Android’s ExifInterface only supports writing orientations to JPEGs, so
for now that’s all I’m starting with. We should investigate other open
source image writers and considering using one that supports other 
formats.

Related to bumptech#3673, but not sufficient because there’s clearly a bug but 
all tests here still pass.
sjudd added a commit to sjudd/glide that referenced this issue Jun 1, 2019
Previously we were sometimes using the rotated size and sometimes using
the original size. As a result, some combinations of width, height and
exif orientation were decoded with unexpected sizes.

Fixes bumptech#3673
@mrtry
Copy link
Author

mrtry commented Jun 1, 2019

@sjudd
Thank you.

What version of Android were you using?

The problem was confirmed in 5.1, 9.0.
But I think it is an issue independent of versions.

@mrtry
Copy link
Author

mrtry commented Jun 13, 2019

@sjudd
Thank you for resolve this issue. 🙏
When will it be released? 🙇

sjudd added a commit to sjudd/glide that referenced this issue Sep 24, 2021
Android’s ExifInterface only supports writing orientations to JPEGs, so
for now that’s all I’m starting with. We should investigate other open
source image writers and considering using one that supports other 
formats.

Related to bumptech#3673, but not sufficient because there’s clearly a bug but 
all tests here still pass.
sjudd added a commit to sjudd/glide that referenced this issue Sep 24, 2021
Previously we were sometimes using the rotated size and sometimes using
the original size. As a result, some combinations of width, height and
exif orientation were decoded with unexpected sizes.

Fixes bumptech#3673
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants