stomita/ios-imagefile-megapixel

detectVerticalSquash bug for transparent PNG

Opened this issue · 2 comments

av01d commented

There's an issue when using megapix-image.js on some transparent PNG's.
The issue is described in detail here: dropzone/dropzone#813
I managed to find and fix the problem, it's a 1 character fix.
In the detectVerticalSquash function, change this:

var data = ctx.getImageData(0, 0, 1, ih).data;

to this:

var data = ctx.getImageData(1, 0, 1, ih).data;

That's all. The library will work as before, and the problem with transparent PNG's is now fixed.

Hi, the changes you're suggesting are for the function detectVerticalSquash which is not used for PNG files, only for image/jpeg ones (see #18)

However, playing with the image http://i.imgur.com/lxfQQqa.png as pointed in dropzone/dropzone#813 I was able to reproduce the stretch problem, which is being caused here from the detectSubsampling function, that one is indeed used for any image.

For the sake of, i tried to apply the same kind of fix:

return ctx.getImageData(0, 0, 1, 1).data[3] === 0;

to this:

return ctx.getImageData(1, 0, 1, 1).data[3] === 0;

but it doesn't seems to fix the problem, kinda odd.

in my case as well detectVerticalSquash function is called from renderImageToCanvas() method

i fixed it by commenting out some code
var alpha = data[(py - 1) * 4 + 3];
//if (alpha === 0) { //that fixes issue when it cant save png with transparent screen
// ey = py;
//} else {
sy = py;
//}
didnt find any bad influence yet but needs more testing :)