goker-dev / canvasResize

Javascript Canvas Resize Plugin. It can work both with jQuery and Zepto. It's compatible with iOS6 and Android 2.3+
http://gokercebeci.com/dev/canvasresize
Other
377 stars 87 forks source link

Very big images choke. #12

Open fidergo-stephane-gourichon opened 11 years ago

fidergo-stephane-gourichon commented 11 years ago

Big images (straight from the camera on certain Apple devices) are reported to be incompletely processed by canvasResize, and memory exhaustion is suspected to be the culprit.

Looking at the code, I see it basically delegates the bulk of the work to HTML canvas drawImage(), which is a good idea (performance-wise -- quality is another matter). As a side effect, images smaller than 1024x1024 get exactly one call to drawImage() (plus the value added of all your code -- workaround bugs, etc).

In a search for ways to reduce memory consumption, I'm considering reducing tile size (currently set by var d = 1024 in source) to e.g. 512. It would mean 4 times more calls to drawImage(), which should not be a problem, but a 4 times smaller tmpCanvas (256kpixels instead of 1Mpixel), hence reduced memory consumption.

  1. What do you think about this attempts to reduce memory consumption ?
  2. Is the value d=1024 carefully selected with reasons to keep it that way (e.g. browsers known to optimize algorithms for this size) or not ?