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

Crashes with every file larger than aproximately around 200 KB #16

Open
johannesjo opened this issue Dec 12, 2013 · 4 comments
Open

Crashes with every file larger than aproximately around 200 KB #16

johannesjo opened this issue Dec 12, 2013 · 4 comments

Comments

@johannesjo
Copy link

Using angular 1.2.0 I ran into the issue that chrome and also firefox tend to crash for every file a little larger than a few Kilobytes. Any idea how to circumvent that?

@mrsean2k
Copy link

I'm not certain if this is the same issue, but on Chrome / Angular, the performance drops off severely for even moderately sized images.

I believe I've traced the issue to the doResizing function:

  var doResizing = function(imageResult, callback) {
      createImage(imageResult.url, function(image) {
         var dataURL = resizeImage(image, scope);
          imageResult.resized = {
              dataURL: dataURL,
              type: dataURL.match(/:(.+\/.+);/)[1],
          };
          callback(imageResult);
      });
  };

executing that particular regular expression on the dataURL.match line takes a great deal of resource - on a 32Gb iMac, it was taking minutes at a time to process a ~1Mb file, and could easlly appear as if it had crashed. I had to ignore injunctions to kill the page 3 or 4 times but it does complete eventually.

Fortunately the fix is easy, using the DataURI spec. as a reference, just replace the match with a simple substring:

  var doResizing = function(imageResult, callback) {
      createImage(imageResult.url, function(image) {
          var dataURL = resizeImage(image, scope);
          var imageType = dataURL.substring(5, dataURL.indexOf(';'));
          imageResult.resized = {
              dataURL: dataURL,
              type: imageType
          };
          callback(imageResult);
      });
  };

This has reduced the processing time to < 1 sec. for everything I've tried it on so far.

@boxxxie
Copy link

boxxxie commented Mar 18, 2014

can you do a PR?

@mrsean2k
Copy link

Hi, unless I've made a mess of it, I should already have added one, PR#25 I think? Unfamiliar with the process so apologies if I've got things out of sequence.

@boxxxie
Copy link

boxxxie commented Mar 18, 2014

sorry, i don't see the PR being referred to in this issue. so it wasn't obvious.

#25
000a7ff

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

3 participants