Is it possible to get image type (gif, png, jpeg, etc.) with src like this?
<img src="http://d1aviatl7dpuhg.cloudfront.net/image/url/64/aHR0cDovL3BpeGNtc2FkbWluLnBpeGFibGUuY29tL3dwLWNvbnRlbnQvdXBsb2Fkcy8yMDE1LzA3L3NoYXJrLmpwZw==">
or created by new Image()
constructor.
Haven't found anything helpful in W3 specs.
I guess that a separate "XHR get src" is sort of a solution, but maybe there is a better way?
Update: all sorts of XRHs are failing because of CORS, so ajax won't work here.
Img src Not Working That means, when a web page loads, the browser has to retrieve the image from a web server and display it on the page. The broken link icon means that the browser could not find the image. If you've just added the image, then check that you included the correct image URL in the source attribute.
call(document. getElementsByTagName('img'), function(img) { return img. src; });
The <img> tag creates a holding space for the referenced image. The <img> tag has two required attributes: src - Specifies the path to the image. alt - Specifies an alternate text for the image, if the image for some reason cannot be displayed.
The following works when run in an extension (which doesn't have CORS restrictions)
I've been exploring this same question, what works is the following:
src
as a blob blob.type
Code sample (with async/await and fetch API):
async function getImageBlob(imageUrl) {
const response = await fetch(imageUrl)
return response.blob()
}
const blob = await getImageBlob("http://path.to.image.com")
blob.type // Image Content-Type (e.g. "image/png")
http://www.andygup.net/easily-find-image-type-in-javascript/
I think you may get some help from this page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With