https://kotlinlang.org logo
#android-architecture
Title
# android-architecture
u

ursus

03/31/2019, 4:17 PM
How do you guys deal with thumbnails in apps? Whats the best way of future proofing this? Should the app tell backend what resolution the screen is and backend scale the image accordingly, or rather backend provide N sizes and app picks the best one? Do you also recalculate this based on current resolution?
m

Michael Bernier

04/01/2019, 12:32 PM
we use a service called cloudinary, which takes care of cropping, resizing and caching images, we pass it the size and density we need depending on device and network quality. Then when the user goes into the picture viewer, we download a non cropped, higher quality picture
u

ursus

04/01/2019, 4:01 PM
and how do you know the size? isnt size - aspect ratio constant and the size changes based on density you provide? (which you get from resources)
but then the backend kind of needs to know about the usecase how is it displayed in "dps", right, thats kind of silly?
or maybe required? im confused on this
m

Michael Bernier

04/01/2019, 4:04 PM
yeah, size is constant, I only send the density I need
1x, 2x, 3x
u

ursus

04/01/2019, 4:26 PM
ok, but that presumes that the thumbnails are for you specific usercase in app -- say avatar image, which is square
if you change design to rectangle, then thumbnails need to be regenerated on backend right?
or if you make the imageview bigger, then image that used to fit will be small, sinze you are still 1x density for example
m

Michael Bernier

04/01/2019, 5:19 PM
that’s why we use an external service, we don’t need to setup anything, it caches request the first time, and then serve the cache version
u

ursus

04/02/2019, 12:55 PM
Sure but you have to provide square source image
and precalculate its source size too.. i.e 1x is 30x50 etc
m

Michael Bernier

04/02/2019, 1:03 PM
we provide the source image, the service does Center Cropping for us, we don’t precalculate anything, we just use the view size displayed on screen
with Glide or Picasso it’s done automatically
u

ursus

04/02/2019, 9:00 PM
no no, I mean that the source image for the cloud service has to be say 500x500, and app provides that it wants 1x density, i.e. divide it by some factor, so it gets served 100x100 for example
i.e. the density just commands the factor, not the actual size, hence the original has to kind-of know about the usecase -- how big in dps is the element in app .. extreme example original image is 3000x3000, app tells its mdpi, and 3000x3000 asumed is xxxhdpi, so it gets divided by factor or lets say 4x, so it gets served 750x750 .. for 24dp avatar
which is obviously wasteful on the network
m

Michael Bernier

04/02/2019, 11:51 PM
You also pass in the size you want the image in, so if you have 100dp x 100dp imageView, you with hdpi you will receive a 200px x 200px cropped image
you can also just pass the width, or height and ratio
r

Rok Koncina

04/03/2019, 11:45 AM
We use GraphQL where we ask for the specific size. We calculate the size (px) locally, so that the server doesn't have to know that "the request came from Android device with hdpi"
u

ursus

04/04/2019, 4:16 PM
@Michael Bernier if I pass in the actual size in pixels, i.e. you read it via imageView.getWidth etc, then whats the point of the density? irelevantn now
@Rok Koncina yea exactly
but how do you do it, I mean, do you provide precise image view size, and server gives you the closest match, i.e. bucket, or should It resize to precisely the pixels you want?
m

Michael Bernier

04/04/2019, 4:30 PM
the server does the cropping/resizing
r

Rok Koncina

04/04/2019, 4:52 PM
In our case we get the closest match, which is (atm) enough for us
3 Views