Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can not get the full image after compress the image that user toke #40

Open
Hanruis opened this issue Dec 11, 2014 · 0 comments
Open

can not get the full image after compress the image that user toke #40

Hanruis opened this issue Dec 11, 2014 · 0 comments

Comments

@Hanruis
Copy link

Hanruis commented Dec 11, 2014

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);
  }

 }

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant