eltos / PasteIntoFile

Paste clipboard data into files and copy file contents directly via hotkey or context menu
MIT License
87 stars 6 forks source link

Small images are wrongly detected as Vectors and end up deformed. #44

Closed ShivaSouza closed 5 months ago

ShivaSouza commented 5 months ago

When Copy/Pasting small images, the program seems to incorrectly detect it as vectors, when saving those as PNG, they end up being deformed

Here is the image when copied and pasted directly on github: image

Here is what shows up when using Paste Into File, it wrongly detects as a emf file. image

And finally, when selecting PNG (or BMP, JPG, etc...) and saving the file, the file ends up deformed (this deformity also shows in preview): 2024-04-24 12-34-59

Thank you!

eltos commented 5 months ago

The windows clipboard usually contains multiple formats at a time. Depending on where you copied the file from, there probably was not only a bitmap, but also an emf version in the clipboard (or maybe a link to a file in your /tmp directory), otherwise pasteintofile hadn't offered you this option. You can use NirSoft's “Inside Clipboard” to list all the formats in your clipboard.

This being said, the deformation might be related to conversation between formats, the background colour change indicates loss of transparency due to a format which does not support it. I could check the priority order for conversion, other than that it's hard to tell without knowing what all exactly was in your clipboard at the time.

ShivaSouza commented 5 months ago

Hi @eltos Eltos, thank you for your answer! And apologies, you're correct!

It seems like it's something specific to copying and pasting from Photoshop (I'm latest version, couldn't test on old ones) and you're correct, it seems like Photoshop adds a ton of stuff to the clipboard... the more you know! All my other softwares (irfanview,aseprite, etc...) don't have any issues.

I was incorrect in assuming it was just small images, it seems like anything copied from photoshop ends up as emf. And when saving, it's somewhat deformed/differently sized? I'm attaching a zip with the image I copied on photoshop, and how it ended up being saved as emf but... somewhat smaller (from 1000px to 963px)

Files.zip

And here is what is on the clipboard, when copying from photoshop. As you've mentioned, it seems like there is a ton of extra stuff. image

I'm not sure if this is a issue exclusively to my photoshop or if it's a common thing. It would be nice if we could use the tool with photoshop, but if not, no issue!

Thank you!

eltos commented 5 months ago

So, you have a bitmap (bmp) and metafile (emf) in your clipboard. Not sure why photoshop uses a different image size for the latter, but it might be related to the fact that metafile is a vector image format and not intended for pixel raster images in the first place (even though it supports it).

PasteIntoFile tries to use the "best" format available on the clipboard for the extension you ask for. For emf this is the metafile, for bmp the bitmap. For other formats it is not so easy. I implemented it such that if you select png (or gif, pdf, tif) then it will choose the metafile and convert it to png. The reason is that both support transparency, but bitmaps don't, so the conversion from bitmap to png is lossy if the image involves transparency. For jpg however the bitmap format is chosen, as jpg does not know transparency either.

Now in your special case, this heuristic fails due to the difference in pixel size, causing the metafile to png conversation to introduce some undesired deformation, where maybe the bitmap to png conversation might have been preferable, as the image has a white background anyhow. However, this tool is not an image converter, it's made on a best-effort basis with the intention to be as simple as possible and can not be expected to handle such strange variations in pixel size.

At some point I might implement a picker for the user to not only choose the file extension, but also the source format from the clipboard. Then you could explicitly choose "bitmap > png". The question is, if it's worth it, cause it adds complexity and is contradictory to the goal of being "as simple as possible"? Happy to hear your opinion on this.

For time being, I would suggest you use the bmp format in your case and do any further conversion with a dedicated tool if required.

ShivaSouza commented 5 months ago

At some point I might implement a picker for the user to not only choose the file extension, but also the source format from the clipboard. Then you could explicitly choose "bitmap > png". The question is, if it's worth it, cause it adds complexity and is contradictory to the goal of being "as simple as possible"? Happy to hear your opinion on this.

This is a good question, and it makes sense to keep things as simple as possible. Would creating a "special case" for Photoshop.exe be something you consider? I think it would be a middle ground of keeping things simple, but still dealing with the Photoshop Issues. Since the Bitmap sizing is correct, could a special case of: "If this is coming from Photoshop.exe, force a non vector approach" or "get the dimensions from the Bitmap"

But of course, only if you think it's "worthy it". But if not, no worries, at least on my end I just paste into irfanview and copy again, could probably even make a simple macro for this if the need arises. But I can see that people who use Photoshop would be happy with a solution for this. I think some tools like Figma use this approach (as they support Vectors as well), while Microsoft Word I've tested and has the same issue with dimensions.

Up to you really! And thank you for the detailed response!

eltos commented 5 months ago

I'm not in favour of any application specific special cases, especially not if it's to work around such quirks. Sorry.

ShivaSouza commented 5 months ago

No worries, it's your call.

Thanks anyway!