mattiasw / ExifReader

A JavaScript Exif info parser.
Mozilla Public License 2.0
737 stars 88 forks source link

How to extract metadata from HTMLImageElement? #305

Closed a0s closed 3 months ago

a0s commented 3 months ago

Description

So, i have an HTMLImageElement() or already loaded Image()

const image = new Image()
image.src = '...'
image.onload = function() {
 ExifReader.load(...) ????
}

How can i get exif inside callback? I didn't find any example in readme or missed it?

mattiasw commented 3 months ago

Hi!

Here are a couple of previous questions about the same thing: https://github.com/mattiasw/ExifReader/issues/184 https://github.com/mattiasw/ExifReader/issues/167

The summary is that you have to load it again with ExifReader.load(image.src) which should take the image from the browser cache. Make sure the server is setting the correct CORS headers or that the image is located on the same server as the page.

a0s commented 3 months ago

Thank you, it works perfect!