Free Trial
10 days, no credit_card

<< More Tutorials

How to read Exif data in json format from an image in Javascript using rethumb?

To read Exif data in json format from an image in Javascript use the following code:

<html>
    <head>
        <script language = "JavaScript">
        window.onload = function()
        {
            function createCORSRequest(method, url)
            {
                var xhr = new XMLHttpRequest();

                if ("withCredentials" in xhr)
                {
                    xhr.open(method, url, true);
                }
                else if (typeof XDomainRequest !== "undefined")
                {
                    xhr = new XDomainRequest();
                    xhr.open(method, url);
                }
                else
                {
                    xhr = null;
                }

                return xhr;
            }

            var xhr = createCORSRequest('GET', "http://api.rethumb.com/v1/exif/all/http://images.rethumb.com/image_exif_1.jpg");
            
            if (xhr)
            {
                xhr.send();

                xhr.onload = function()
                {
                    document.getElementById('pre1').innerHTML = xhr.responseText;
                };

                xhr.onerror = function()
                {
                    document.getElementById('pre1').innerHTML = 'There was an error!';
                };
            }
            else
            {
                document.getElementById('pre1').innerHTML = 'CORS not supported';
            }
        }
        </script>
    </head>

    <body>
        <pre id="pre1"></pre>
    </body>
</html>

Start using this example now

Use the following commands to get started:

$ git clone https://github.com/rethumb/rethumb-javascript-examples.git
$ cd rethumb-javascript-examples
$ open read-exif-data-in-json.html

More examples using Javascript