banner
sakiko🐘

sakiko🐘

可怜的孩子 不再胆怯
twitter
twitter
discord server

About the troublesome issue of uploading images when publishing local Markdown documents to various platforms.

Recently, I have been enjoying writing various things and then uploading them to various platforms. It gives me a great sense of accomplishment. However, because I write in Markdown locally, it becomes a bit troublesome when uploading.

For example, when uploading to Bilibili, if I copy the entire text from Typora and paste it into the Bilibili editor, the images in the article will not be copied. I have to manually upload them... It's not a big deal if there are only a few images, but it becomes really tiring if there are many.

After uploading with a bit of effort, I gradually discovered that I can directly copy and paste image files in the corresponding positions. Although it's a bit more convenient, I still have to find the right position in the document and find the corresponding image in the folder. It takes a long time and strains my eyes... Can it be even more convenient?

Oh, I think I have a solution: use a Python script to continuously monitor the clipboard. After copying the image link in the uploaded Markdown document, Python can obtain the image link, and then copy the image file to the clipboard and paste it.

This way, as long as I copy the image link in the Markdown document, the image will be automatically uploaded. How great!

By the way, I realized that when copying the entire text from Typora and pasting it into the Bilibili editor, not only the images are not copied, but even the image links are not copied. This is a problem. Does it mean that I wasted over a hundred lines of code?

With the attitude of not giving up on my previous efforts, I explored a bit more. I found out why the image links were not copied in Typora. It's because the text of the image links is interpreted as images in Typora, so the text cannot be copied (annoying, I can't copy both the image and the text).

Since that's the case, let's modify the image links so that they are not interpreted as images but only as text.

Hehe, just use the shortcut Ctrl+H to replace it.

It's easy to see the difference from the previous one. I tried it and it works perfectly! (It's even more noticeable, which is great)

I tried uploading it, and it's great. Triple-click the mouse to select the entire line, then press Ctrl+C, and the long link will automatically turn into an image. Sugoi!

This is where the article ends. I originally wanted to end it here, but I thought a little more: can animated images be uploaded too?

I was skeptical because when I wrote the copy_img function to copy the image to the clipboard, I referred to an article that converts the image to a bitmap "BMP" and writes it to the clipboard. But a bitmap is not an animated image.

Reference: Copying Images to the Clipboard in Python https://www.cnblogs.com/JYB2021/p/14696503.html

I tried it, and it didn't work... This won't do, otherwise the previous images won't be animated!!

I looked at another article that used a different method and tried it. This time it worked, thanks to the author!

Copying PNG Images to the Clipboard in Python 3 https://blog.csdn.net/MowChan/article/details/122823017

Okay, it's really useful. I'm going to upload now!

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.