abo-abo / org-download

Drag and drop images to Emacs org-mode
1.08k stars 78 forks source link

Paste from Clipboard on Windows possible? #75

Closed poulpoulsen closed 4 years ago

poulpoulsen commented 6 years ago

Hello, i use org-download with drag and drop images on Windows and it works. But paste an image is not. The following message appears and no image is loaded. File "IMG_20180527_084811_2018-06-12_19-24-13.jpg" is now a task attachment. Under the org-heading appears the following,but no image. I toggle with org-toggle-inline-image, but nothing happens. " :PROPERTIES: :ID: 49578a89-39ed-425c-810c-c4b085699000 :Attachments: IMG_20180527_084811_2018-06-12_19-24-13.jpg :CREATED: <2018-06-12 Di 19:24> :END:

+DOWNLOADED: file:C%3A/Users/Held/Desktop/IMG_20180527_084811.jpg @ 2018-06-12 19:24:13

+attr_html: :width 100px

* Any clues?

Regards Poul

TobiasZawada commented 6 years ago

Hi abo-abo, FYI: This question is connected to a question answer pair about pasting base64-encoded images in org-mode on https://emacs.stackexchange.com.

There the variables org-download-screenshot-method and org-download-screenshot-file are used for function org-download-screenshot-img.

In a comment the OP gave following statement:

hello, i checked again with imagemagick installed. Unfortunately it is not working as aspected. If i copy an image into the windows clipboard and tried to insert the image with C-S-y. The following message occur: "convert: NoBitmapOnClipboard ' @ error/clipboard.c/ReadCLIPBOARDImage/158. convert: NoImagesDefined ~/screenshot.png' @ error/convert.c/ConvertImageCommand/3275. let: Opening input file: No such file or directory, c:/Users/Held/screenshot.png" Is it possible to insert the image via clipboard and copy/paste? Regards – space_held

I find the message convert: NoBitmapOnClipboard rather interesting.

poulpoulsen commented 6 years ago

hello, FYI: org-download-screenshot-method is set to imagemagick/convert org-download-screenshot-file is set to ~/screenshot.png

in my config file: (setq org-download-method (quote attach)) (setq org-download-screenshot-method "convert clipboard: %s")

Regards Poul

TobiasZawada commented 6 years ago

Imagemagick is compiled with MS-VisualStudio. Therefore we need an additional expand-file-name to expand the tilde character ~ to the users home directory.

@poulpoulsen Could you please retry with org-download-screenshot-file set to "c:/Users/Held/screenshot.png" and report the result here?

It may even be that you need to set org-download-screenshot-file to "c:\\Users\\Held\\screenshot.png". Please also try that if the first attempt fails. (That should actually not be necessary since the default value "/tmp/screenshot.png" also uses forward slashes.)

poulpoulsen commented 6 years ago

hello, i try it with the double slashes. Result is: "convert: NoImagesDefined `c:\Users\Held\screenshot.png' @ error/convert.c/ConvertImageCommand/3275. url-scheme-default-loader: Unknown URL scheme: c" Does it help? Regards Poul

TobiasZawada commented 6 years ago

@poulpoulsen Dear Poul, issue #57 describes a similar problem. In some way it answers two questions:

  1. Pasting images from the clipboard should work in principle on Windows. (Otherwise #57 would not have been closed.)
  2. The problem there was that @technician77 misinterpreted the documentation. I would even say that this is a documentation bug and a misnaming of org-download-screenshot for Windows. The Emacs command org-download-screenshot does not take the screenshot. It just pastes an image that is already on the clipboard as attachment into an org-buffer. But, I assume that you know that and that you are facing a different problem.
TobiasZawada commented 6 years ago

@poulpoulsen It may be that you copy image data to the clipboard that cannot be read by Imagemagick, e.g., handles to emf and wmf images. I cite here http://www.multipole.org/discourse-server/viewtopic.php?t=20303:

I'm trying to use ImageMagick in conjunction with VBA to create PNGs from Excel via the clipboard. If the data is copied to the clipboard normally, ImageMagick works perfectly. However, if the data is copied to the clipboard through VBA, ImageMagick fails to see any image data on the clipboard.

The VBA code in question is:

Code: Select all

Range().CopyPicture xlScreen, xlPicture

which copies the contents of to the clipboard as an image.

With this data, ImageMagick returns:

Code: Select all

C:>convert clipboard:myimage -density 150 -units pixelsperinch testpls.png convert.exe: no bitmap on clipboard `myimage' @ error/clipboard.c/ReadCLIPBOARDImage/138. convert.exe: missing an image filename `testpls.png' @ error/convert.c/ConvertImageCommand/3016.

With the same data,

Code: Select all

iview32 /clippaste /convert=testIV.png

generates the image properly.

Installed version is ImageMagick-6.7.5-0-Q16-windows.zip (portable package) on Windows 7 (x64), running Excel 2010 (32-bit).

Easiest way to reproduce is by opening Excel, putting some random data in a cell, selecting said cell, and in the VBA Immediate window running:

Code: Select all

Selection.CopyPicture xlScreen, xlPicture

This will put the image data on the clipboard for analysis. Top

Werty Posts: 58 Joined: 2010-08-06T05:37:36-07:00 Authentication code: 8675308

Re: Possible bug w/ "clipboard:"

Post by Werty » 2012-02-13T09:12:30-07:00 Are you sure you are feeding it image data and not just a Handle to the data ?

Try…

Code: Select all

Convert rose: clipboard:

then…

Convert clipboard: image.jpg

^this works for me, having no image data on the clipboard gives me the same error as yours, so it seems you arent getting the correct data on your clipboard. Windows 7 user Top

odditude
Posts: 2
Joined: 2012-02-07T16:23:55-07:00 Authentication code: 8675308

Re: Possible bug w/ "clipboard:"

Post by odditude » 2012-02-14T18:01:56-07:00 OK - got it to work (you need to use xlBitmap instead of xlPicture). xlBitmap was giving me bad data in both programs before, likely due to Excel misbehaving.

Using InsideClipboard, though, I verified that xlPicture is passing just handles to a WMF and EMF; xlBitmap provides actual DIB and DIBv5 data.

poulpoulsen commented 6 years ago

hello, thank you for that information, but it i'm a little bit confused what i could do with it. I paste jpg or png images, that should work fine, because drag and drop through org-download works fine. How could i check if pasting clipboard data into emacs is working?

Regards Poul

et2010 commented 6 years ago

Hi, @poulpoulsen @TobiasZawada

FYI, Irfanview on Windows can be used to take a screenshot. It's free for personal use. I've just created a PR for this purpose. You can try it. https://github.com/abo-abo/org-download/pull/76

test2

falematte commented 4 years ago

It looks like this problem is not only windows related. I am not able to do the same in linux.

abo-abo commented 4 years ago

@falematte Please elaborate. Write down a list of steps for me to follow.

falematte commented 4 years ago

Thank you for the answer. I am able to drag and drop images but pressing C-y the image saved in the clipboard is not inserted in the buffer.

abo-abo commented 4 years ago

@falematte

I have just tested it on Linux like this. I set org-download-screenshot-method to one of the available settings:

(setq org-download-screenshot-method
      "xclip -selection clipboard -t image/png -o > %s")

Everything works as expected.

MorphicResonance commented 4 years ago

Org-download screenshot works on Windows 10. Got screenshot from clipboard and pasted into org file. Tested with windows default Snip & Sketch tool and convert from imagemagick Took screenshot by windows Snip & Sketch tool. It takes screenshot and puts it into the clipboard. Picture is exist and can be pasted somewhere (checked on imgur).

org-download-screenshot-method was set to run imagemagick and process clipboard. Tried with Infartview also. Part of config.el from doom emacs. (setq org-download-screenshot-method "convert clipboard: %s") (setq org-download-method '+org/org-download-method))

Steps taken to make it works. • install imagemagick for windows. During installation check box to install convert.exe image • make sure you have imagemagick path to your system variables.

falematte commented 4 years ago

@falematte

I have just tested it on Linux like this. I set org-download-screenshot-method to one of the available settings:

(setq org-download-screenshot-method
      "xclip -selection clipboard -t image/png -o > %s")
* I open an image in GIMP and copy to clipboard.

* Open an Org file and M-x `org-download-screenshot`

Everything works as expected.

Everything works perfectly for me!

zzamboni commented 4 years ago

For reference (since I ended up on this thread while figuring out how to do this), on macOS a similar technique can be used to paste an image from the clipboard, by setting org-download-screenshot-method to "/usr/local/bin/pngpaste %s" (pngpaste can be installed from Homebrew). Then you can copy a screenshot or image to the clipboard and use M-x org-download-screenshot to insert it.

abo-abo commented 4 years ago

Thanks, all, for the comments and suggestions. Please test the new org-download-clipboard, which should work for GNU/Linux, Windows, and OSX.

Exr0n commented 3 years ago

Hi, this was closed a while ago but I'm confused about how to use org-download-clipboard. I couldn't find any documentation or even a mention of it except here... where can I learn how to install and use it?

zzamboni commented 3 years ago

@Exr0n if it helps, here's my configuration: https://github.com/zzamboni/dot-doom/blob/master/doom.org#capturing-images

(some Doom Emacs-specific stuff there, like after! and map!, but which should be easily switchable to vanilla versions)

hydev commented 1 year ago

Just for reference, on Windows it is possible to use org-download-screenshot without using imagemagick convert, but by using powershell:

(setq org-download-screenshot-method "powershell -c Add-Type -AssemblyName System.Windows.Forms;$image = [Windows.Forms.Clipboard]::GetImage();$image.Save('%s', [System.Drawing.Imaging.ImageFormat]::Png)")