I’m trying to rescale Image before loading it into a texture.
After research, i found that using a canvas in context 2D (create on the fly) is a one of solution to rescale image:
function scaleImage(imageUrl, resizeWPourcent = 0, resizeHPourcent = 0){
var canvas = document.createElement("canvas");
var ctx = canvas.getContext("2d");
var img = new Image();
img.onload = function () {
canvas.width = img.width * resizeWPourcent;
canvas.height = img.height * resizeHPourcent;
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
}
img.src = imageUrl;
var texture = new THREE.Texture( canvas );
texture.wrapS = THREE.RepeatWrapping;
texture.wrapT = THREE.RepeatWrapping;
texture.needsUpdate = true;
return texture;
}
My image is displayed on a quad in a 3D space but sadly everything is black…
I’ve read that it could be a pb of non square image but i’m using webgl 2 render…