I don’t think Fabric.js is an intruder here, because when I add time warnings, it only takes 2-3 seconds. However, the code used here is:
applyTo: function(canvasEl) { var context = canvasEl.getContext('2d'), imageData = context.getImageData(0, 0, canvasEl.width, canvasEl.height), data = imageData.data, len = imageData.width * imageData.height * 4, index = 0, average; while (index < len) { average = (data[index] + data[index + 1] + data[index + 2]) / 3; data[index] = average; data[index + 1] = average; data[index + 2] = average; index += 4; } context.putImageData(imageData, 0, 0); },
So, if it is not an intruder, then the intruder is the putImageData function.
Is there a way to increase / optimize this function so that it works with a 5000x5000 image, of course, in less than 15 seconds?
If not, is there a way to set a “working” icon, which is deleted only after putImageData is completed via jQuery, because at the moment it is deleted after 2 seconds, because the Fabric.js code ends faster?
source share