jupyter-widgets-contrib / ipycanvas

Interactive Canvas in Jupyter
https://ipycanvas.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
688 stars 64 forks source link

Supporting grayscale images from numpy #346

Closed AnyaPorter closed 4 months ago

AnyaPorter commented 5 months ago

Would it be possible to add the option to give a 2D numpy array to put_image_data() for a grayscale image? As it is you have to either turn it into a 3d array with equal values or convert to an Image widget first. It looks like a case of adding another condition to binary_image in utils that says to use the PNG format to save, but I'm not sure if I'm missing places that would be affected.

AnyaPorter commented 4 months ago

I made a fork and tried implementing that change and grayscale support is very simple--I would like to contribute if you are open to it so I am also opening a pull request for this (#348)