+ 1
How to import an image in the code playground?
pls someone help me on this I want to imaport an image in my code playground
2 Answers
+ 2
you cant but you can do refer by src="http://www." and write path for the image which you want
+ 6
There ars several ways:
1. Image tag in HTML (easiest way)
<img src="url of the image" width=xxx* height=xxx*> This tag does not have an end tag
*these are attributes that can change the image, but you can change the resolution in CSS too.
2. Canvas image (I would recommend this, only if you create a game or an animation with canvas)
HTML:
<canvas id="canvas"></canvas>
JS:
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d")
ctx.beginPath()
ctx.drawImage(img, width, height)
Again, img has to be a string in its url form.
If you want to crop the image, you will need more arguments
ctx.drawImage(img, sx, sy, swidth, sheight, x, y, width,height)
The arguments starting with "s" are the clipped part of the image.
Hope this helps!