Closed hutterm closed 10 months ago
Thanks for reporting the issue.
Seems like using Get-Clipboard -Format Image
is indeed not a reliable method. I've changed the code to use .NET commands instead, which should be available on most Windows systems. Can you see if fix/clipboard-not-working-on-windows resolves your issues? If you're using Lazy, just set the branch
option accordingly.
I will probably add support for win32yank
as an optional dependency as well. I suspect it provides better performance and reliability.
ok, seems like the clipboard can be read with the fix branch, but I still get the message, "Could not save image to disk."
did some more tests with the new powershell commands you changed. I can successfully execute them in the console, but only if I have write access and the directories exist. a '~' is not recognized by the command as a valid directory it seems filename without a path is also not working, so it seems it needs a full path, that exists and has write access
Can you please try to execute the following command:
powershell.exe "Add-Type -AssemblyName System.Windows.Forms;Add-Type -AssemblyName System.Drawing;$img = [System.Windows.Forms.Clipboard]::GetImage();$img.Save('image.png', [System.Drawing.Imaging.ImageFormat]::Png);"
In the following environments:
I suspect it will work in the command prompt, and not the latter options. Remember to copy an image to the clipboard before executing the command.
I can successfully execute them in the console, but only if I have write access and the directories exist.
That's taken care of by a different function, see: https://github.com/HakonHarnes/img-clip.nvim/blob/1aef484fc2302f8e81d9595f2a972bb635b81715/lua/img-clip/fs.lua#L79
further tests: with the added base64 option I get: "Could not get base64 string." while still opening the File name input. pressing enter after that it says "Could not save image to disk."
- Command prompt
prompt copied works
- Powershell 5.1
prompt fails with the whole powershell.exe in the front but works with just the stuff in the quotes
- Powershell 7.3
prompt fails, even with just the stuff in the quotes:
PS> Add-Type -AssemblyName System.Windows.Forms;Add-Type -AssemblyName System.Drawing;$img = [System.Windows.Forms.Clipboard]::GetImage();$img.Save('image.png', [System.Drawing.Imaging.ImageFormat]::Png);
MethodInvocationException: Exception calling "Save" with "2" argument(s): "A generic error occurred in GDI+."
I think the issue is related to what the default command-line shell is on your system. What is the output of :set shell?
within neovim?
ah, that could be it! I set mine to pwsh
Should be able to account for that, I'll ping you when I have a (hopefully) working solution!
@hutterm Can you see if it works now? If not, set debug = true
and paste the output of :messages
please.
didn't work with message clipboard content is not an image. :messages
:
Shell: pwsh
Command: Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.Clipboard]::GetImage()
Exit code: 0
Output:
[32;1mTag : [0m
[32;1mPhysicalDimension : [0m{Width=93, Height=189}
[32;1mSize : [0m{Width=93, Height=189}
[32;1mWidth : [0m93
[32;1mHeight : [0m189
[32;1mHorizontalResolution : [0m96
[32;1mVerticalResolution : [0m96
[32;1mFlags : [0m335888
[32;1mRawFormat : [0mMemoryBMP
[32;1mPixelFormat : [0mFormat32bppRgb
[32;1mPropertyIdList : [0m{}
[32;1mPropertyItems : [0m{}
[32;1mPalette : [0mSystem.Drawing.Imaging.ColorPalette
[32;1mFrameDimensionsList : [0m{7462dc86-6180-4c7e-8e3f-ee7333a7a483}
Ah, I see. Try again with the latest changes.
awesome! that worked, thanks for your dedication!
it always says "Clipboard content is not an image"
I'm suspecting it's the windows powershell command not working.
PS> Get-Clipboard -Format Image
returnsGet-Clipboard : A parameter cannot be found that matches parameter name 'Format'
both in pwsh.exe (7.3.10) and powershell.exe (PSVersion 5.1.22621.2506)here is a linked issue about the missing format: https://github.com/PowerShell/PowerShell/issues/12290