Open In App

D3.js image() Function

Improve
Improve
Like Article
Like
Save
Share
Report

The d3.image() function in D3.js is a part of the request API that is used to fetch the images from any given image URL. If init is also given in the function then it sets any additional properties on the image before loading the image.  

Syntax:

d3.image(input[, init]);

Parameters: This function accepts a single parameter as mentioned above and described below:

  • input: It takes the address of the image to be fetched.

Return Values: It returns the image from the image URL.

Below examples illustrate the D3.js image() Function in JavaScript.

Example1:

HTML




<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta
            name="viewport"
            path1tent="width=device-width, 
                       initial-scale=1.0"/>
        <title>D3.js image() Function</title>
    </head>
    <style></style>
    <body>
        <script src=
        </script>
        <script src=
        </script>
        <script src=
        </script>
  
        <script>
            d3.image("https://robohash.org/image", 
                     { crossOrigin: "anonymous" }).then((img) => {
                console.log(img);
            });
        </script>
    </body>
</html>


Output:

Example 2:

HTML




<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta
            name="viewport"
            path1tent="width=device-width, 
                       initial-scale=1.0"/>
        <title>D3.js image() Function</title>
    </head>
    <style></style>
    <body>
        <script src=
        </script>
        <script src=
        </script>
        <script src=
        </script>
  
        <script>
            d3.image(
              { crossOrigin: "anonymous" }).then((img) => {
                document.body.append("Image using d3.image()");
                document.body.append(img);
            });
        </script>
    </body>
</html>


Output:



Last Updated : 17 Aug, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads