amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

How to show alternate image if source image is not found?

Open evivz opened this issue 10 years ago • 10 comments

I Am using amp-img tag. I won't implement above functionality. Can you please help?

evivz avatar Feb 29 '16 06:02 evivz

@evivz To clarify: Are you asking for a way to show a fallback (backup alternate image) in the case that the src specified by amp-img is not found (i.e. 404)?

Is there some reason why it cannot be reliably known whether the image is available?

rudygalfi avatar Feb 29 '16 17:02 rudygalfi

I am serving images from third party services and many times they are dead. Before I could update their replacement in my server many people visit my website. I want to serve them alternate image temporarily.

evivz avatar Feb 29 '16 19:02 evivz

@rudygalfi @evivz @sriramkrish85 We can consider fallback element for image in this case. But it can't be an infinite thing. I.e it'd only be one attempt -> one fallback -> that's it.

<amp-img src="...">
  <amp-img fallback src="default.png"></amp-img>
</amp-img>

It doesn't only have to be image as a fallback - it could be an SVG or even a basic DIV with text.

If this is agreeable, we can explore this option.

dvoytenko avatar Mar 01 '16 18:03 dvoytenko

Yes this will work.

evivz avatar Mar 07 '16 11:03 evivz

Any updates by when this feature/request will be added?

evivz avatar Mar 08 '16 05:03 evivz

i'll take over this one. should be able to start on it late tomorrow or thursday.

erwinmombay avatar Mar 08 '16 23:03 erwinmombay

Thanks, @erwinmombay . Just for posterity: for the complete solution this issue will be blocked on #2261.

dvoytenko avatar Mar 08 '16 23:03 dvoytenko

I am not able to get this fallback.. how should i use this fallback feature? <amp-img src = "<%= post.ProfileImage %>" width = "40" height = "40" placeholder> <amp-img fallback src = "/images/broker-profile.jpg" width = "40" height = "40"> </amp-img> </amp-img>

kishanj918 avatar Mar 18 '16 04:03 kishanj918

@kishanj918 so it is currently in opt in canary and a user will have to turn on "dev channel" in cdn.ampproject.org/experiments.html do try it out if it solves your problem. if there are no issues it will be released to production by Thursday next week

erwinmombay avatar Mar 18 '16 04:03 erwinmombay

@erwinmombay That worked. Thanks

kishanj918 avatar Mar 18 '16 04:03 kishanj918