在 Internet Explorer 中调整 Base64 编码图像的大小
以下函数在 Chrome 和 Firefox 中完美运行,但在 Internet Explorer 中失败。我添加了 obj_* 分配以在 IE 中调试它,.height() 或 .width 方法不起作用。 jpgmulti 流不能用于 IE 吗?我是否必须为 IE 调用不同的名称?下面确认了在 MacOSX 上与 Chrome 和 FF 的配合。
function append-base64image(jpgmulti) {
var object = jQuery.parseJSON('{'+jpgmulti+'}');
for (var content in object) {
// create element for image
var image_roll = document.createElement("img");
// ad attributes to element
image_roll.setAttribute("src", "data:image/jpeg;base64,"+object[content]);
// calculate aspect ratio for preview:
var obj_height = object[content].height;
var obj_width = object[content].width;
var div_obj_width = obj_width/150;
var height_resize = obj_height/div_obj_width;
image_roll.setAttribute("width", 150);
image_roll.setAttribute("height", height_resize);
document.getElementById("previews").appendChild(image_roll);
}
}
The following function works perfectly for me with Chrome and Firefox, while it fails with Internet Explorer. I added the the the obj_* assignments to debug it in IE, the .height() or .width methods do not work.
Is the jpgmulti stream not usable for IE? Do I have to call it different for IE? Below is confirmed working with Chrome and FF on MacOSX.
function append-base64image(jpgmulti) {
var object = jQuery.parseJSON('{'+jpgmulti+'}');
for (var content in object) {
// create element for image
var image_roll = document.createElement("img");
// ad attributes to element
image_roll.setAttribute("src", "data:image/jpeg;base64,"+object[content]);
// calculate aspect ratio for preview:
var obj_height = object[content].height;
var obj_width = object[content].width;
var div_obj_width = obj_width/150;
var height_resize = obj_height/div_obj_width;
image_roll.setAttribute("width", 150);
image_roll.setAttribute("height", height_resize);
document.getElementById("previews").appendChild(image_roll);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论