Resize Image Javascript Client. If you use this below example that shows to preview the of resizing an image. Draw in canvas var ctx elem getcontext 2d.
Scale the image to 600 width and keep aspect ratio var scalefactor resize width el target width. Html head title resize image title head body div input id imagefile type file input type button value resize image onclick resizeimage img src id output div script type text javascript function resizeimage var filestoupload document getelementbyid imagefile files. Null var settings extend defaults options.
Create a file reader var reader new filereader.
If control prop tagname tolowercase input control attr type tolowercase file control attr accept image. Imag0 height imag0 height 2 imag0 is the name of the image. Elem height el target height scalefactor. How to resize image size using canvas and convert into base64 encoded string data urls and blob in javascript.