html2canvas ios8,javascript - iOS8 Mobile Safari Canvas issue - Stack Overflow

I have the following code:

function resizeBase64Img(base64, coeficient) {

var sizeGetter = new Image();

sizeGetter.src = base64;

var height = sizeGetter.height*coeficient;

var width = sizeGetter.width*coeficient;

var canvas = document.createElement("canvas");

canvas.width = width;

canvas.height = height;

var context = canvas.getContext("2d");

var deferred = $.Deferred();

$("").attr("src", base64).load(function() {

context.scale(width/this.width, height/this.height);

context.drawImage(this, 0, 0);

deferred.resolve($("").attr("src", canvas.toDataURL()));

});

return deferred.promise();

}

Basically what it does is it grabs an image from an input[type=file] and then uses canvas to resize the image before appending it to the body. This works fine on Chrome in OSX.

In Mobile Safari (iOS 8.1) the appended image has an empty src * sometimes *, some images so work, but most fail. I tried also using the desktop safari to troubleshoot, and it simply stops working when it gets to the canvas related instructions. I've looked around for known bugs, but the only thing I could find was this, although I don't seem to breaking the rules stated there.

Is this just simply poor canvas support on iOS8? Have I missed something?

EDIT #1:

Apparently there's also another issue, which I'll be looking at. (Stackoverflow won't let me post the link)

EDIT #2:

The error seems to be this:

var canvas = document.createElement("canvas");

canvas.width = width;

canvas.height = height;

Canvas is not setting its width and height properly. They remain as undefined as per the inspector in Mobile Safari.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值