HakonHarnes / img-clip.nvim

Effortlessly embed images into any markup language, like LaTeX, Markdown or Typst
MIT License
443 stars 7 forks source link

Compress img size before base64 #51

Closed LintaoAmons closed 5 months ago

LintaoAmons commented 5 months ago

I think most of the case, we don't need high quality img in our markdown file, as along as the content is readable.

So if we can have one more option to compress the image before save it as base64 format into the markdown file.

HakonHarnes commented 5 months ago

Thanks for reporting. I think the best solution here is to allow the user to specify a custom preprocessing command (i.e. a command that is executed before the image is embedded or saved). This would involve adding the following option:

This should bring full flexibility to the user. Thoughts on this @LintaoAmons?

LintaoAmons commented 5 months ago

Yeah! Definitely better

I think providing user some sample functions would help a lot. People like me don't familiar with how to deal with pictures, so it would be very kind of you

HakonHarnes commented 5 months ago

I've implemented this in the feat/process-cmd branch. You can set the branch option in lazy.nvim and update to try it out. Set the process_cmd option to try it out.

Your config should look like this:

    default = {
      embed_image_as_base64 = true,
      process_cmd = "convert -quality 85 - -",
    },

@LintaoAmons How is this working out for you? If you face issues please post the output of the :ImgClipDebug command.

LintaoAmons commented 5 months ago

I'm trying to test on my machine, but I'm facing some errors.

I have tried the main branch and also revert to previous commit, the issue still exists. So I think there's something went wrong with my laptop instead of this plugin.

image

***%20Error%20creating%20a%20JP2%20color%20space:%20falling%20back%20to%20sRGB

do you have any hints of this error?

HakonHarnes commented 5 months ago

Seems like an unrelated issue, yes. Can you switch to the main branch for now and open a new issue?

In the new issue, please post your config, OS and output of ":ImgClipDebug" after the error occurs. Also, try disabling base64 embedding and see if the error persists.