Add images to README.md on GitHub

2019-01-04 04:04发布

Recently I joined GitHub. I hosted some projects there.

I need to include some images in my README File. I don't know how to do that.

I searched about this, but all I got was some links which tell me to "host images on web and specify the image path in README.md file".

Is there any way to do this without hosting the images on any third-party web hosting services?

25条回答
走好不送
2楼-- · 2019-01-04 04:39

Try this markdown:

![alt text](http://url/to/img.png)

I think you can link directly to the raw version of an image if it's stored in your repository. i.e.

![alt text](https://raw.githubusercontent.com/username/projectname/branch/path/to/img.png)

Edit: just noticed comment linking to article which suggests using gh-pages. Also, relative links can be a better idea than the absolute URLs I posted above.

查看更多
地球回转人心会变
3楼-- · 2019-01-04 04:43

JUST THIS WORKS!!

take care about your file name uppercase in tag and put PNG file inroot, and link to the filename without any path:

![Screenshot](screenshot.png)
查看更多
闹够了就滚
4楼-- · 2019-01-04 04:44

You can just do:

git checkout --orphan assets
cp /where/image/currently/located/on/machine/diagram.png .
git add .
git commit -m 'Added diagram'
git push -u origin assets

Then you can just reference it in the README file like so:

![diagram](diagram.png)

查看更多
你好瞎i
5楼-- · 2019-01-04 04:45

I usually host the image on the site, this can link to any hosted image. Just toss this in the readme. Works for .rst files, not sure about .md

.. image:: https://url/path/to/image
   :height: 100px
   :width: 200 px
   :scale: 50 %
查看更多
迷人小祖宗
6楼-- · 2019-01-04 04:45

Consider using a table if adding multiple screenshots and want to align them using tabular data for improved accessibility as shown here:

high-tea

If your markdown parser supports it you could also add the role="presentation" WIA-ARIA attribute to the TABLE element and omit the th tags.

查看更多
够拽才男人
7楼-- · 2019-01-04 04:46

You can also use relative paths like

![Alt text](relative/path/to/img.jpg?raw=true "Title")
查看更多
登录 后发表回答