App icon indicating copy to clipboard operation
App copied to clipboard

[HOLD for payment 2021-09-17] Image preview is blurry when uploading a long image (pay on 9/17)

Open isagoico opened this issue 5 years ago • 25 comments

If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Action Performed:

  1. Navigate to a conversation
  2. Upload this image
  3. Check the image preview in chat

Expected Result:

Image should not be blurry on preview.

Actual Result:

Image is blurry in preview.

Workaround:

Can the user still use Expensify without this being fixed? Have you informed them of the workaround?

Platform:

Where is this issue occurring?

  • Web
  • iOS
  • Android
  • Desktop App
  • Mobile Web

Version Number: 1.0.93-0

Logs: https://stackoverflow.com/c/expensify/questions/4856

Notes/Photos/Videos: Any additional supporting documentation

image

image

Expensify/Expensify Issue URL:

View all open jobs on GitHub


@mallenexpensify https://expensify.slack.com/archives/C01GTK53T8Q/p1630683790390300

Text in screenshot is blurry and unreadable when sent/received in NewDot, deets in

isagoico avatar Sep 04 '21 00:09 isagoico

Triggered auto assignment to @thienlnam (Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.

MelvinBot avatar Sep 04 '21 00:09 MelvinBot

Proposed Solution:

Whenever we upload image there is a corresponding thumbnail generation logic is there at server side. So server side thumbnail generation logic is designed in such a way that, it will cap thumbnail width or height to max 1024px. (I can say this based on the various image I uploaded for testing and analysed generated thumbnail size).

So any image dimension fall into three types as under, so server will generate thumbnail accordingly.

CaseA: If uploaded image is landscape (i.e. width > height) then it will cap thumbnail max width to 1024px and generate thumb height according to original image aspect ratio.

CaseB: If uploaded image is portrait (i.e. height > width) then it will cap thumbnail max height to 1024px and generate thumb width according to original image aspect ratio.

CaseC: If uploaded image is square (i.e. height === width) then it will cap thumbnail max height or width to 1024px and generate other dimension according to original image aspect ratio.

Now here is calculation: Given sample image is long and its original size is 1314w X 7808h. i.e. this is portrait(h>w). So server will cap thumbnail max height to 1024px (if height > 1024) and generate thumb width as per image aspect ratio.

So server generated thumbHeight: 1024px and thumbWidth=172px ( i.e. (1024 * 1314)/ 7808). This is fine there is not any problem in server side thumbnail generation.

Now here is reason why Image preview blurry for that specific image.

Image preview thumbnail is rendered via ThumbnailImage.js component within chat. As we can see at line 39 const thumbnailScreenWidth = 250; it means it will fix thumb Image width to 250 and calculate height accordingly to render within ui. So within chat ui all image shows as same width.

This works fine if generated thumbnail image width is 250px or larger (so in that case blur will not happen), But here our sample image thumbnail width is 172px, and it is rendering as 250px width, i.e. its width is stretched from 172px to 250px within ui so it become blurry.

https://github.com/Expensify/App/blob/6cd518e81fb60415ba8d4d4a659fdc5dfa95b6fd/src/components/ThumbnailImage.js#L36-L43

Solution 1 - Remove Blur Problem via Ui Logic Update:

We have to update line 39 within ThumbnailImage.js file as under, i.e. if thumb image width less than 250px then we have to consider thumb image width, otherwise consider 250px. So if any thumb image width smaller than 250px then it will render as original thumb width, otherwise render as 250px width.

So after updating this solution it happen that all thumb image those width >=250px will render as same size, and some special case image (e.g. we used specific dimension image in this issue) those thumb width less than 250px will render as smaller width without any blur.


 import lodashClamp from 'lodash/clamp';    // *** import lodash clamp

 updateImageSize({width, height}) { 
     // Width of the thumbnail works better as a constant than it does 
     // a percentage of the screen width since it is relative to each screen 
     const thumbnailScreenWidth = lodashClamp(width, 40, 250);   // *** Clamp 40px to support touch ***

     const scaleFactor = width / thumbnailScreenWidth; 
     const imageHeight = height / scaleFactor; 
     this.setState({thumbnailWidth: thumbnailScreenWidth, thumbnailHeight: imageHeight}); 
 } 

Below is the screen recording that shows how ui looks when Solution 1 implemented, there is not any blur now.

https://user-images.githubusercontent.com/7823358/132100699-596e04ae-2943-4fac-b4a2-5ca116472bfc.mov

Solution 2 - Remove Blur Problem via Server Side Update:

Second solution is to update thumbnail generation logic at server side. i.e. Whenever any thumbnail generated at server side it should be generated in such a way that thumbnail width should not be smaller than 250px and generate thumb height accordingly to original aspect ratio.

So this will solve blur problem for thumb image those will be generated after updating server side logic. But here one thing we have to consider that if some thumb image already generated in the past having width smaller than 250px it needs to flush out and regenerate again during next request for that thumbnail.

So this is all about my analysis and solution for this problem.

I understand that External label not set with this issue. So at present consider this as my suggestion. It will be helpful to someone who handle this issue internally.

If this issue considered as external and my Solution 1 (Remove Blur Problem via Ui Logic Update) accepted then kindly invite me on Upwork once project posted. Here is my upwork profile: https://www.upwork.com/freelancers/~01c718889ed7821f82 Thanks.

PrashantMangukiya avatar Sep 04 '21 16:09 PrashantMangukiya

Triggered auto assignment to @bfitzexpensify (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.

MelvinBot avatar Sep 07 '21 16:09 MelvinBot

Triggered auto assignment to @mountiny (Exported), see https://stackoverflow.com/c/expensify/questions/7972 for more details.

MelvinBot avatar Sep 07 '21 18:09 MelvinBot

@PrashantMangukiya Hi 👋 that is an amazing investigation and description of the problem.

I believe considering Solution 1 should be good enough, but there is one thing I would want us to consider as well. We are now talking about hypothetical and extreme dimensions, but in case of extremely tall image (ie. screenshot of entire long page), we could end up with very narrow image preview, which would be hard to touch on mobile device.

Thus, I believe it would be beneficial to also add a minimum width cap just in case, which should be around 40px which is a width of UI element comfortable for user to touch. What do you think about this idea? If you agree, could you please incorporate that into your proposal?

I would then be very happy to hire you for this job on Upwork once this gets resolved.

mountiny avatar Sep 08 '21 13:09 mountiny

Hi @mountiny Thank you for the message.

I think what you suggest 40px min width cap is a good point. Not sure why I missed that point after doing this details level research. Any way good catch from your side.

Let met update my proposal to incorporate it. I will update you as soon as incorporated within few minutes. So you can proceed further to post job on Upwork. Thank you.

PrashantMangukiya avatar Sep 08 '21 13:09 PrashantMangukiya

@PrashantMangukiya Great! Thank you!

After watching the screenshare video once more, I have noticed the picture has still been kind of blurry. I am not sure if it is the picture itself. Could you please make sure with some different sharp image, that this proposed solution works as expected and share a screenshot of the thumbnail and the original picture too. Possibly comparison between thumbnail on main and your proposed solution?

Thank you very much!

mountiny avatar Sep 08 '21 14:09 mountiny

@mountiny Thank you for the message.

Sample image used to reproduce this issue consist text based information so when thumbnail generated at server side blur may be introduce due to text info within image. But we can not do assumption, So let me do some more detail investigation and make sure there is not any hidden issue other place and thumbnail is rendering as expected size.

I will also do testing on long sharp image so we get more idea about it. I will update you as soon as more result comes. Thanks.

PrashantMangukiya avatar Sep 08 '21 14:09 PrashantMangukiya

@PrashantMangukiya Job post on Upwork is here.

bfitzexpensify avatar Sep 08 '21 14:09 bfitzexpensify

@bfitzexpensify I can not see job although logged in to upwork. It shows below screen. It looks like this is internal/private job etc. Can you invite me on this job, may be it solve the problem. My upwork profile is https://www.upwork.com/freelancers/~01c718889ed7821f82

Screenshot 2021-09-08 at 8 22 33 PM

PrashantMangukiya avatar Sep 08 '21 14:09 PrashantMangukiya

Ah you're right! Sorry about that — here is the right link.

bfitzexpensify avatar Sep 08 '21 15:09 bfitzexpensify

Hi @mountiny ,

I did more investigation on this issue using extra long color image. Here is Sample1 and Sample2 image used for this. I will suggest to @mountiny, @isagoico, and @bfitzexpensify also to reproduce this additional issue using sample1 and sample2 image link, So I can make sure this issue happen for everyone.

Additional issue is that some padding shows at top and bottom of extra long image as shown below screenshot (Blur issue is already there and Solution I suggested in my proposal works for that) But below additional issue connected with long height image, So I am thinking we have to also investigate and correct this additional issue togheter.

@bfitzexpensify I will do more research on this additional issue and once get solution thereafter submit my proposal on Upwork, so it will be ok? Because at present I dont know how much research it will need.

Below is additional issue, i.e. some padding generated at top and bottom border of extra long image.

Screenshot 2021-09-08 at 9 39 56 PM Screenshot 2021-09-08 at 9 41 38 PM Screenshot 2021-09-08 at 9 42 18 PM

IOS:

IMG_9306

IMG_9307

PrashantMangukiya avatar Sep 08 '21 16:09 PrashantMangukiya

Yep, I'm also able to reproduce that. image

isagoico avatar Sep 08 '21 17:09 isagoico

@PrashantMangukiya Good investigation! I assume the white block padding issue prevails even with your proposed changes here, correct me if I am wrong.

I think the best way to go with that new issue is to follow these steps once you make sure it is actual bug.

Don't forget about the minimal width restriction as well in your proposal and feel free to start a PR!

mountiny avatar Sep 09 '21 10:09 mountiny

Hi @mountiny, yes that white padding issue remain although I correct image blur problem.

I added clamp logic within my solution 1 as per your suggestion. Here is link https://github.com/Expensify/App/issues/5092#issuecomment-912999085 Please suggest any other thing need to take care. If everything ok then I will submit proposal on upwork to proceed.

As you can see below screenshot, padding issue still there after solving image blur problem. I also notice that top bottom padding increase as image become more narrow. I will contune research on this white padding and share solution for this new issue as soon as found something.

Screenshot 2021-09-09 at 5 02 02 PM Screenshot 2021-09-09 at 4 59 50 PM Screenshot 2021-09-09 at 4 59 32 PM

I also notice that this top bottom padding exist for too long height image that I used. For normal long image it shows as expected.

I think it is better to create another issue for this top bottom white padding. @isagoico what you suggest? Should I submit bug request within Slack as per new rule, our you will create new issue for this bug and mention my name as bug suggester. It will be ok whatever you suggest.

Thanks.

PrashantMangukiya avatar Sep 09 '21 12:09 PrashantMangukiya

@PrashantMangukiya Ah you have updated the original comment, sorry, my bad! thank you for that.

Your proposal seems good to me for this issue. Feel free to submit a proposal on Upwork and create a PR for this. Great job!

Should I submit bug request within Slack as per new rule, our you will create new issue for this bug and mention my name as bug suggester. It will be ok whatever you suggest.

I think it is safe to post it in the channel, @isagoico will definitely mention you as a suggester that way! You won't miss that.

mountiny avatar Sep 09 '21 13:09 mountiny

@mountiny Sure I will post bug request in the slack channel. @bfitzexpensify I submitted proposal on upwork. Kindly accept it. Thank you.

PrashantMangukiya avatar Sep 09 '21 13:09 PrashantMangukiya

Just to make it formal. @bfitzexpensify we are good to hire Prashant for this job. Thank you for handling that 🙇

@PrashantMangukiya You will be assinged to this issue right after that.

mountiny avatar Sep 09 '21 15:09 mountiny

Offer sent!

bfitzexpensify avatar Sep 09 '21 16:09 bfitzexpensify

@bfitzexpensify just accepted offer. thanks. Also thanks @mountiny for suggesting to set 40px cap for image width. I will prepare and submit pr within a day.

PrashantMangukiya avatar Sep 09 '21 16:09 PrashantMangukiya