ios-imagefile-megapixel icon indicating copy to clipboard operation
ios-imagefile-megapixel copied to clipboard

detectVerticalSquash bug for transparent PNG

Open av01d opened this issue 9 years ago • 2 comments

There's an issue when using megapix-image.js on some transparent PNG's. The issue is described in detail here: https://github.com/enyo/dropzone/issues/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.

av01d avatar Mar 01 '16 12:03 av01d

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 enyo/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.

diegocr avatar Mar 10 '16 18:03 diegocr

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 :)

zulalay avatar Mar 14 '16 16:03 zulalay