imgur-migrate

Imgur Migrate

According to Imgur’s recent announcement, some images will be deleted from their platform after May 15, 2023.

To avoid losing your images, you can use this tool to replace all Imgur links in your Markdown files with local images.

What it does

This tool will find all Imgur links in the markdown files under your directory, download them, and replace your Imgur links with interal links to local images.

Suppose you have 1 Imgur lank in README.md and 2 in docs/System Design.md:

.
├── README.md
└── docs
    └── System Design.md

becomes

.
├── README.md
├── README-1.png
└── docs
    ├── System Design.md
    ├── System Design-1.png
    └── System Design-2.png

In docs/System Design.md for example, it will replace ![text](https://i.imgur.com/123456.png) with ![[System Design-1.png]] or ![text](System Design-1.png), where the downloaded image name = <markdown file name>-<auto-incremented number>.

How to run

Install

git clone https://github.com/dlccyes/imgur-migrate

For Linux or MacOS

sh install.sh

Now you the command imgur-migrate should be available. Note that it may take a while when running the first time.

For Windows

I didn’t create a binary for Windows, so you’ll have to run the python file directly, or use WSL.

pip3 install -r requirements.txt

Replace all the imgur-migrate commands below with python3 imgur_migrate.py.

See usage

imgur-migrate -h

Mode

There are 2 modes, wikilink and mdlink.

The 2 modes will convert ![text](https://i.imgur.com/123456.png) to

Specify the mode with -m or --mode:

imgur-migrate -m wikilink
imgur-migrate --mode mdlink

If -m or --mode is not specified, it will use the default mode wikilink.

Run the whole directory

Run it against the current directory

imgur-migrate

Or run it against a specific directory

imgur-migrate <path/to/your/directory>

Run a file

Run it against a specific file inside a directory

imgur-migrate <path/to/your/directory> <filename>

Test

You can test it on the example directory in this repo.

imgur-migrate example

Limitations

I create this simple tool for my own needs, so it isn’t very featureful.

If you have other external image links, they won’t be replaced.

Also, it will only search for links starting with https://i.imgur.com/ e.g. https://i.imgur.com/123456.png.

It will only search for markdown files, and only for Imgur links that are in ![]() or ![text](). Meaning, if you have HTML-style embedded images in your markdown file, they won’t be replaced.

Does not escape codeblock

If your Imgur link is in codeblock or inline code, it will still be replaced.