hydrogen icon indicating copy to clipboard operation
hydrogen copied to clipboard

Copy/save image

Open huyiqun opened this issue 8 years ago • 22 comments

When I use %inline mode to plot something, it is not possible to copy or save the image, but only to view it in atom. Is it possible to add such functionality or what is the best workaround on this? I currently connect a qtconsole to the existing hydrogen kernel, and run the plot code there in order to directly right click for copying and saving. Just wonder if this is by any chance doable in atom.

Also, a quick related question: when the output is one line, it does not pop up a small window that has option for copying or opening in a file. Can this be changed?

Thanks!

huyiqun avatar Mar 31 '16 01:03 huyiqun

On 31/03/16 02:57, huyiqun wrote:

When I use %inline mode to plot something, it is not possible to copy or save the image, but only to view it in atom. Is it possible to add such functionality or what is the best workaround on this? I currently connect a qtconsole to the existing hydrogen kernel, and run the plot code there in order to directly right click for copying and saving. Just wonder if this is by any chance doable in atom.

I think this can be easily done. I'll mark this issue as an enhancement.

Also, a quick related question: when the output is one line, it does not pop up a small window that has option for copying or opening in a file. Can this be changed?

If you click on a one-line bubble, Hydrogen will copy its content to the clipboard.

n-riesco avatar Mar 31 '16 07:03 n-riesco

Which language are you using?

For example in python with matplotlib you can do this very easily with plt.savefig('example.pdf')

lgeiger avatar Mar 31 '16 08:03 lgeiger

I'm guessing you're looking for browser style "right-click -> save image"?

screenshot 2016-03-31 07 33 08

rgbkrk avatar Mar 31 '16 14:03 rgbkrk

I am using python and looking for exactly what @rgbkrk has shown. I know saving to a file would be one option, but just wonder if a temporary copy and paste is possible as I am quite used to such functionality. :)

huyiqun avatar Mar 31 '16 15:03 huyiqun

+1 for this!

what @rgbkrk is suggesting is exactly what I am looking for, as I am running my code on a remote notebook, hence plt.savefig() would save the file to the remote computer, not on my local machine...

nbara avatar Jan 10 '17 10:01 nbara

+1!

tobiasbj avatar Mar 09 '17 12:03 tobiasbj

+1! This feature is critical for efficiency improvement when organizing analytics results

weimindong2016 avatar Aug 09 '17 00:08 weimindong2016

In general it would be great if the plugin would simply allow to save an html copy of the script and the inlined outputs.

holgerbrandl avatar Sep 29 '17 11:09 holgerbrandl

+1!

duzaichuan avatar Oct 27 '17 09:10 duzaichuan

+1

dwSun avatar May 09 '18 06:05 dwSun

+1

Earthson avatar May 16 '18 13:05 Earthson

I've labeled this as up-for-grabs because no one is known to be working on this yet there are lots of +1s. If you want to tackle it, please do.

It looks like the API you'd want to use is the Atom ContextMenuManager, likely scoping it to .output-area img (or something similar).

rgbkrk avatar May 16 '18 16:05 rgbkrk

if you highlight and run both lines:

plt.plot(data)
plt.savefig(path)

with hydrogen, it will save the .png of the plot in the given path. When i did the above, executing them line by line it did not save the fig.

bridgesra avatar Jun 08 '18 22:06 bridgesra

+1

Dirivian avatar Aug 07 '18 16:08 Dirivian

@rgbkrk Is the transfer of image content to the clipboard a different process than the transfer of text to the clipboard? I.e. is it difficult at all to put onto the clipboard, or is it just not exposed in the UI?

kylebarron avatar Sep 24 '18 02:09 kylebarron

I think it's an Atom thing we have to somehow expose, based on experience with context menus for Electron.

rgbkrk avatar Sep 24 '18 16:09 rgbkrk

I looked a little into the APIs. It appears that Hydrogen currently uses Atom's clipboard API, which seems to only support writing text and not an image.

Atom's clipboard API seems to be separate from Electron's clipboard API, which does allow for writing an image to the clipboard, but it must be a nativeImage, which seems to only allow PNG or JPG formats.

kylebarron avatar Sep 24 '18 19:09 kylebarron

I was able to get around this by opening the element inspector, selecting the image element, and copying the dataURI to my browser. So long as you have the <img>, you should be able to pass its src into NativeImage.createFromDataUrl to prep the underlying png for export.

SKalt avatar Mar 21 '19 15:03 SKalt

+1

bertrandcz avatar Oct 14 '19 09:10 bertrandcz

+1 I was very sad to find out that Jupyter didn't have this functionality...

jazzlw avatar Oct 30 '19 19:10 jazzlw

+1 Particularly when working with remote kernels copying images to your clipboard would be tremendously helpful.

ttxtea avatar Nov 26 '20 17:11 ttxtea

I've been using a hacky work around for this when working on a remote kernel (and so savefig saves the plots on the server).

  1. Open the inspector (cmd-option-i on Mac)
  2. Select the inspect element icon in the top of the inspection pane (icon is a mouse in a box)
  3. Click on the plot you want to save
  4. Right-click the html item/tag that is now highlighted in the inspection pane (should start with <img alt src="...)
  5. Click copy link address
  6. Paste that address into a new browser tab
  7. Save or copy the plot from there

It's really not ideal, but for one-off plots, I find it faster than saving to your remote server and retrieving via scp.

Screen Shot 2021-03-05 at 3 10 08 PM

mebrunet avatar Mar 05 '21 20:03 mebrunet