I am developing a REST API using Django
. I collect the information in a JSON
. With the attributes string
there is no problem.
My question is with the images. Right now I grab the images using a UEL, but there is only one image. On the other hand, if we add images to an Android project, we have the possibility/need to upload images in different densities.
What solution do you propose in this regard? How do you manage this point?
I would solve it in the following way:
First get the pixel density of the device:
Next step, build the
Uri
toREST/ful
obtain the image with the required density passing it as a parameterGET
(low,med,high,xhigh)In the images I would add an identifier to know what density they belong to, using as a pattern
nombreimage_<densidad>.<ext>
Depending on the request, one image or another is sent.
Code extracted from: SO How to retrieve same image to android phones with different screen densities+json
It is strictly necessary to have the ability to download images with different sizes, because if you only download one size it will not work as it would if you had the corresponding images in the folders:
it is a bit tricky trying to scale an image on a device since it depends on the density of the same as the sample, it would be displayed in the wrong size on some devices.
The option could be to determine which image to use depending on your density, although from experience it doesn't display similarly as if it were in your density folder in
/res
In these cases, where the image is obtained via url, I use phpThumbs
project page
It will allow you to scale images with many crop options, zoom, compression, etc.
It also incorporates a cache system, with the consequent improvement in times...
Greetings ^^