Would it be possible to make a package out of your implementation?
Yes. Personally, I would not install it as-is though, too little benefit (equivalent to 15-line of code) but maybe after expanding to cover more cases it could be useful.
Or would it be possible to add this feature to an already existing library (e.g. IPython or Ipywidgets)?
I could see a case for including something more generic (%capture_images) in IPython-contrib, but I am not a maintainer there so the decision on accepting it would be up to somebody else ![]()
Saving the output with
%%capture_pngdoes not display the image in Jupyter. That is also the case when using the%%capturemagic.
Well, it’s called capture, this is what capture functions do. If it should display output it ought to be called tee_png (after tee) or save_png. But, as you correctly noticed the modifications needed to display the outputs are minimal (though the order can be lost if you also have non-image outputs - I don’t have a solution for that of top of my head).
Possibly - it’s barely 200 lines of code (+ maybe few hundreds more in helper methods); personally I would accept the dependency (on PIL or pillow) ![]()