collective / collective.behavior.amp

Support for Accelerated Mobile Pages (AMP) in Plone.
5 stars 2 forks source link

How can we get size information of an external image? #29

Open hvelarde opened 8 years ago

hvelarde commented 8 years ago

When transforming an <img> tag into a <amp-img> we need to provide size information and remove any class attribute; we need to think how to solve this without adding too much complexity to the package.

kakshay21 commented 7 years ago

@hvelarde I think if src="resolveuid/979bede6b93e46d386be493d852ed744" then we can use


   with Image.open(src) as img:
       height,width=im.size ```
and we need to import PIL
and one more option we have is by numpy 
kakshay21 commented 7 years ago

Oh...never mind

hvelarde commented 7 years ago

I think this will need to partially request the external image and guessing its dimensions; but we need to be careful to not download the whole file as it can be big and will keep a thread busy until is done..

kakshay21 commented 7 years ago

Height and width are just to know the aspect ratio of the image. We can do one thing set any default values for height and width so that it fits every image and add layout ="responsive" You must see this https://stackoverflow.com/questions/42220861/how-to-deal-with-images-with-an-undefined-height-and-width-attribute-for-amp-pag @hvelarde

hvelarde commented 7 years ago

we can't do that if we don't know the real aspect ratio; we still need to read a chunk of the image for that.