最近我加入了GitHub。我在那里主持了一些项目。

我需要在README文件中包含一些图像。我不知道该怎么做。

我搜索了一下,但得到的只是一些链接,告诉我“在web上托管图像并在README.md文件中指定图像路径”。

是否有任何方法可以在不在任何第三方网络托管服务上托管图像的情况下做到这一点?


当前回答

只需在README.md中添加一个<img>标记,并将相对src添加到存储库。如果您没有使用相对src,请确保服务器支持CORS。

它之所以有效,是因为GitHub支持内联html

<img src="/docs/logo.png" alt="My cool logo"/>
# My cool project and above is the logo of it

在此处观察

其他回答

我找到了另一个解决方案,但完全不同,我会解释一下

基本上,我使用标签来显示图像,但我想在单击图像时转到另一个页面,下面是我是如何做到的。

<a href="the-url-you-want-to-go-when-image-is-clicked.com" />
<img src="image-source-url-location.com" />

如果你把它放在彼此的旁边,用一条新的线隔开,我猜当你点击图片时,它会转到一个标签,标签上有你想要重定向的另一个站点的href。

此答案也可在以下位置找到:https://github.com/YourUserAccount/YourProject/blob/master/DirectoryPath/ReadMe.md

使用以下方式显示回购中的图像:

前置域:https://raw.githubusercontent.com/

附加标志:?消毒=真&原始=真

使用<img/>标记

Eample url works for svg, png, and jpg using:

域名:raw.githubusercontent.com/用户名:YourUserAccount/回购:YourProject/分行:YourBranch/路径:DirectoryPath/文件名:example.png

适用于SVG、PNG和JPEG

 - `raw.githubusercontent.com/YourUserAccount/YourProject/YourBranch/DirectoryPath/svgdemo1.svg?sanitize=true&raw=true`

使用后显示的工作示例代码如下:

**raw.githubusercontent.com**:
<img src="https://raw.githubusercontent.com/YourUserAccount/YourProject/master/DirectoryPath/Example.png?raw=true" />

<img src="https://raw.githubusercontent.com/YourUserAccount/YourProject/master/DirectoryPath/svgdemo1.svg?sanitize=true&raw=true" />

raw.githubusercontent.com:

谢谢:- https://stackoverflow.com/a/48723190/1815624- https://github.com/potherca-blog/StackOverflow/edit/master/question.13808020.include-an-svg-hosted-on-github-in-markdown/readme.md

在新的Github UI中,这对我有用-

示例-在文件夹(myFolder)中提交image.png,并在README.md中添加以下行:

![Optional Text](../main/myFolder/image.png)

只需在里面的README.md文件中写下代码[Anyname](图像路径)

![Screenshot](screenshot1.png)

对于使用大小管理选项上载图像:

<img src="a.jpg" alt="J" width="200"/>