Resize Image Data Javascript. Let s see an example and try to discuss each part of the code. In this tutorial we will create a simple resize image using javascript.
Function randomcat let number math floor math random 20. Create a html5 canvas element const elem document createelement canvas. Function showimagepreview input image preview after select image if input files input files 0 var filerdr new filereader.
Img onload function var canvas document createelement canvas.
You can resize your pictures and images without changing their quality. Ctx drawimage img 0 0 canvas width canvas height. Send this data to wherever you need it var data canvas. Set the width and height of the canvas to match the new dimensions of the image.