1
How do I use draw image in Javascript
woodyloody (6)

I have been wondering how to add images to a canvas and found the drw image function. I was wondering why it would not work when i have tried using it in my code and i was wondering if someone could help me.

https://repl.it/@woodyloody/Html-and-JS-Practice

You are viewing a single comment. View All
2
heyitsmarcus (280)

Hey @woodyloody,

The reason you're not seeing the image is that you have to link the JavaScript file to your HTML page. You need to put a script tag in the bottom of your body with a src attribute to the script.js file like this:

<html>
<body>

<p>Image to use:</p>

<img id="scream" width="220" height="277"
src="s.jpeg" alt="The Scream">

<p>Canvas:</p>

<canvas id="myCanvas" width="240" height="297"
style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.
</canvas>
<script src="script.js"></script>
</body>
</html>

And if you always leave the script at the bottom of the page, you don't need to use window.onload to start your code.

If this solves your problem, please consider upvoting and marking my answer as the accepted answer to close this question. But, I'll continue answering any questions you may have.