can not get the full image after compress the image that user toke
Opened this issue · 0 comments
Hanruis commented
Hi, stomita:
I use your solution to fixed the ratio bug in ios. But i came across a new problem. That is after compress the image that user toke by iphone camera, and upload. I can not get the full compressed image -- some part of image missing .
I search on goole , and can not found any detail about this problem.
Have you come across this problem or have any idea about it ?
Sorry about my english. may you understand my word : )
Here my code :
` function compress (source_img_obj, quality, scale, output_format) {
var mime_type = "image/jpeg";
var cvs = document.createElement('canvas');
var w = source_img_obj.naturalWidth * scale
var h = source_img_obj.naturalHeight * scale
cvs.width = w;
cvs.height = h;
var ctx = cvs.getContext("2d");
ctx.drawImage(source_img_obj,0,0,w,h);
if (typeof output_format !== "undefined" && output_format == "png") {
mime_type = "image/png";
}
// 修复IOS
if( navigator.userAgent.match(/iphone/i) ) {
var mpImg = new MegaPixImage(source_img_obj);
mpImg.render(cvs, { maxWidth: w, /*maxHeight:h, */quality: quality});
return cvs.toDataURL(output_format, quality-0.3);
}
// 修复android
if( navigator.userAgent.match(/Android/i) ) {
var encoder = new JPEGEncoder();
return encoder.encode(ctx.getImageData(0,0,w,h), quality*100);
}
}
`