在表格中获取图片时在“图片”标签中设置高度和宽度

时间:2019-01-25 05:35:23

标签: javascript jquery

  1. 我在jsp中声明了一个div。
  2. 我正在向服务器发送请求,并在表中的base 64中获取图像,例如

  3. 每个时间图像都是可变尺寸的。

所以现在我想在javaScript中设置图像的高度和宽度。

脚本代码

function getSignature(signUrl, accountNumber) {

    $.ajax({
    url: signUrl,
    data: ({accountNumber : accountNumber}),
    success: function(data1) {
    $('#signDiv').show();
    $('#signDiv').html(data1[0]);
    enter code here
    }
    });
    }

in jsp I have declared  
and on click fetcing image and howing in

getting response as 

    
        
    

1 个答案:

答案 0 :(得分:0)

您只需加载图像并获取其宽度和高度

var img = new Image();
img.src = "Your base64 image";
if (img.complete) { 
    alert('width: '+img.width);
}
else { 
    img.onload = function() {
       //load if not loaded
alert('width: '+img.width);
    }
}