Answer the question
In order to leave comments, you need to log in
How to find photo sizes for canvasa?
There is a code:
let canvas = document.getElementById('canvas');
function getLinkToImage() {
const url = 'https://api.unsplash.com/photos/random?query=town,Minsk&client_id=КОД';
fetch(url)
.then(res => res.json())
.then(data => data.urls.small)
.then(image => {
if (canvas.getContext) {
let ctx = canvas.getContext('2d');
ctx.clearRect(0, 0, canvas.width, canvas.height);
let pic = new Image();
pic.src = image;
pic.onload = () => {
ctx.drawImage(pic, ?, ?, ?, ?);
}
}
})
}
ctx.drawImage(pic, ?, ?, ?, ?);
Answer the question
In order to leave comments, you need to log in
I think he wants the interest to run nicely.
var count=0;
var interval = setInterval(function(){
console.log(count+' %');
count++;
if(count>100)clearInterval(interval);
},10);
You are iterating from 1 to 100 but returning only the last value. And how is it supposed to be?
On the occurrence pic.oload
(although it may be earlier), see pic.naturalWidth
and pic.naturalHight
or, if these values ​​are suddenly not defined (in older browsers), then pic.width
and pic.hight
, but only if they are not explicitly set via the width
and attributes height
.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question