pixelsorter icon indicating copy to clipboard operation
pixelsorter copied to clipboard

Preserving transparent pixels in image sort.

Open zroper opened this issue 5 years ago • 2 comments

Great app! I've been using it to generate some artwork using .png input images that have transparent backgrounds. Whenever I run those images through the application, the transparent pixels output black. Is there any way to preserve the transparent pixels in the original image so that they are also present in the output?

zroper avatar May 26 '20 01:05 zroper

Hmmm, I haven't looked at this codebase in a while, but based on a cursory look just now a lot of the codebase assumes the image data is in (R,G,B) tuples — specifically all the sorting functions and "key" functions.

it might be as simple as loading the image from PIL w/ a different mode in sort_image_with_cli_args (specifically the get_data() call), and passing in (R,G,B,A) tuples, and hoping most of the code doesn't explicitly require three channels per pixel. I can test this out next weekend when I'm free / feel free to try it out yourself.

rkargon avatar May 26 '20 02:05 rkargon

Thanks for the response! After looking into this, the app is correctly detecting the image mode input (RGBA), but there was this pesky check in pixelsort.py lines 260-261:

  if img.mode != "RGB" and not gif:
        img = img.convert(mode="RGB")

After commenting this out, the alpha pixels are preserved in the output.

zroper avatar Jun 02 '20 18:06 zroper