0

BASE64 img onto Canvas (HTML JavaScript) What is wrong with this piece code please? my image wont display...

async function reduce_image_size(Base64str,MaxWidth=300,MaxHeight=300) { alert('Reduce_Image'); <!-- resized base64= await new Promise((resolve)=> { //--> alert('here0'); var canvas=document.createElement('canvas'); var context = canvas.getContext("2d"); img=new image() alert("here1"); img.src=Base64str; width=img.width; height=img.height; alert("here"); if (width>height) { if (width>MaxWidth) { height=MaxWidth/width; width=MaxWidth;} } else { if (height>MaxHeight) { width=MaxHeight/height; height=MaxHeight; } } img.onload=() => { canvas.width=width; canvas.height=height; resolve(canvas.toDataUrl) } <!-- }) ///--> return Base64str; }

25th Apr 2024, 5:53 PM
Belinda Craill
Belinda Craill - avatar
2 Respuestas
+ 2
Put your code in the playground then share it. Also you have to input the entire base54 string.
26th Apr 2024, 1:53 AM
Chris Coder
Chris Coder - avatar
+ 1
Belinda Craill try to attach your code in Q&A Discussion section like that below. It is easy to solve your code. There are lot of issues in code that you attached already. Remember JavaScript is case-sensitive try to resolve your code in that clue. https://sololearn.com/compiler-playground/Wek0V1MyIR2r/?ref=app
26th Apr 2024, 7:39 AM
`ᴴᵗᵗየ
`ᴴᵗᵗየ - avatar