clipboard-image.nvim icon indicating copy to clipboard operation
clipboard-image.nvim copied to clipboard

Image format and size as new options

Open gzagatti opened this issue 1 year ago • 12 comments

First thanks for creating this very useful plugin.

I have made some modifications to the plugin to allow for alternative image formats and sizes. It is often the case that I want to include an image in JPEG format or in a different size since this can significantly reduce the file size. Also JPEG can be more suitable for photography as you can see from the Adobe comparison. Thus, I added these options to the plugin.

In order to modify the format, the clipboard application must be able to accept a format parameter. This seems to be the case for the Linux and Windows executables. For MacOS, an error will be raised if the user requests a format different than PNG since the current implementation uses pngpaste. We could modify the implementation in MacOS to support different formats.

As for the image size, this PR uses the ImageMagick convert command to modify the image size. Image size modification could be implemented with the img_handler option, but I thought it would be an overkill for something so simple.

gzagatti avatar Aug 08 '22 02:08 gzagatti

I have also added file support to org files.

gzagatti avatar Aug 08 '22 02:08 gzagatti

Sorry for very late reply. I don't think I can accept this pr currently since I don't want this plugin to rely to more external dependencies 🙏‍.

But I plan to write whist-list/planned feature in an issue. And if more people interested in this feature, I will consider to merge it for future version

ekickx avatar Sep 14 '22 06:09 ekickx

That's fine. I will just keep my fork for now as I use the resize utility on a daily basis.

If you prefer, I could do a PR only for the image type which does not introduce any more dependencies and then keep a separate fork with the resizing.

gzagatti avatar Sep 16 '22 02:09 gzagatti

and what about not converting image format on paste, but getting to use initially another image format, for example, I use avif format, and in the clipboard I already have avif format image, but on paste plugin convert in to png.

I changed three lines of code and now plugin dont override it, but I can't get this setting out of the plugin code, because for accomplish this, I need to copy most of the code.

in this case, the plugin does not do any extra work, it simply respects the system's capabilities by adding such an element to the config table, and checking against it in the functions: get_clip_command, is_clipboard_img and get_img_path.

or am I missing something?

lumpsoid avatar Oct 20 '22 05:10 lumpsoid

The get_clip_command at least in my computer (Ubuntu) will run the following:

> xclip -selection clipboard -t TARGETS -o
TIMESTAMP
TARGETS
MULTIPLE
SAVE_TARGETS
text/html
text/_moz_htmlinfo
text/_moz_htmlcontext
image/png
image/jpeg
image/bmp
image/x-bmp
image/x-MS-bmp
image/x-icon
image/x-ico
image/x-win-bitmap
image/vnd.microsoft.icon
application/ico
image/ico
image/icon
text/ico
image/tiff

This gives you a list of possible targets, it does not say which one is the default. Therefore, the program has to choose from this list which format to output. As I can see, there are two options. Either the program chooses or you have to pre-specify the format in the configuration.

The following should save your images in AVIF if you are trying the branch of this PR:

require'clipboard-image'.setup {
   img_format = "avif"
}

gzagatti avatar Oct 21 '22 04:10 gzagatti

@gzagatti thank you for your explanation my reasoning was aimed at why part of this PR has a positive impact on customization, which in my opinion would not interfere with the main part of the plugin @ekickx

lumpsoid avatar Oct 28 '22 06:10 lumpsoid

Sorry for being inactive 🙏‍. I think I can accept this PR except the resize feature.

ekickx avatar Nov 02 '22 16:11 ekickx

I could remove the resize option if not relevant. I think I can easily add to my own configuration via the img_handler.

gzagatti avatar Nov 02 '22 17:11 gzagatti

Yes that would be nice

ekickx avatar Nov 03 '22 02:11 ekickx

I removed the size handler.

For future reference, those who may wish to include a size handler in their configuration:

require'clipboard-image'.setup {
  default = {
  img_handler = function(img)
    os.execute(string.format(
      'mogrify -quality 95 -resize "600x400>" "%s"',
      img.path
    ))
  end
  }
}

gzagatti avatar Nov 04 '22 04:11 gzagatti

Ok now why doesn't the automated test run? I should fix this first 😆

ekickx avatar Nov 07 '22 13:11 ekickx

I have made the changes you suggested and added extra documentation.

gzagatti avatar Nov 12 '22 16:11 gzagatti