提交表单前调整图像大小 HTML5

javascriptweb developmentfront end scripts

要在提交表单前调整图像大小,您需要使用 drawImage() 方法。

缩放原始图像并在画布上的 [0,0] 处绘制缩放后的版本

context.drawImage( img, 0,0,img.width,img.height, 0,0,myWidth,UseHeight );

上面,我们看到了以下内容:

这里,

var myWidth = Math.floor( img.width * Scale );
var myHeight = Math.floor( img.height * Scale );

并且,

var x = Math.floor( ( world.width - myWidth) / 2 );
var y = Math.floor( ( world.height - myHeight) / 2 );

相关文章