最近我加入了 GitHub,在那里托管了一些项目。
我需要在 README 文件中包含一些图片,但不知道该如何操作。
我搜索了一下,但得到的都是一些链接,告诉我“将图片托管在网络上,并在 README.md 文件中指定图片路径”。
是否有不依赖第三方网络托管服务的方法?
最近我加入了 GitHub,在那里托管了一些项目。
我需要在 README 文件中包含一些图片,但不知道该如何操作。
我搜索了一下,但得到的都是一些链接,告诉我“将图片托管在网络上,并在 README.md 文件中指定图片路径”。
是否有不依赖第三方网络托管服务的方法?
虽然GitHub Markdown也可以添加图片,但我建议您使用HTML IMG标签
Github Markdown
![me](https://github.com/samadpls)
HTML标签
<img src='https://github.com/samadpls'/>
只需在README.md文件中将代码写在此处[任何名称](图片路径)
![Screenshot](screenshot1.png)
无需编写任何代码,GitHub上的readme文件现在支持拖放功能。
README.md
文件我通常会在网站上托管图片,这可以链接到任何托管的图片。只需将此放入自述文件即可。适用于.rst
文件,不确定对于.md
文件是否适用。
.. image:: https://url/path/to/image
:height: 100px
:width: 200 px
:scale: 50 %
https://cdn.rawgit.com/<USER>/<REPO>/<BRANCH>/<PATH>/<TO>/<FILE>
https://github.com/jongracecox/anybadge/blob/master/examples/awesomeness.svg
示例嵌入图像:
这是文件的原始链接(仍然不会呈现为图像):
https://raw.githubusercontent.com/jongracecox/anybadge/master/examples/awesomeness.svg
示例嵌入式图像:
使用CDN链接,我可以使用以下方式链接到文件(呈现为图像):
https://cdn.rawgit.com/jongracecox/anybadge/master/examples/awesomeness.svg
示例嵌入图像:
这是我如何在我的README.md
文件和PyPi项目的reStructredText文档(此处)中使用来自我的项目的图像的方法。
您有两种简单的方法可以实现这个操作:
1)使用HTML img 标签,
2)![](您保存图片的路径/图片名称.png)
您可以从打开该图片的浏览器中复制URL以获取路径。如果路径或图片名称中有任何空格问题,请添加 -> %20,就像浏览器一样。
这两种方法都可以使用,如果您想了解更多信息,可以查看我的github -> https://github.com/adityarawat29
![](images/ss_apps.png)
- cdsaenz?sanitize=true&raw=true
<img />
标签raw.githubusercontent.com/
YourUserAccount/
YourProject/
YourBranch/
DirectoryPath/
example.png
适用于SVG、PNG和JPEG格式的图片。
该答案还可以在以下链接中找到: https://github.com/YourUserAccount/YourProject/blob/master/DirectoryPath/ReadMe.md
- `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://dev59.com/UGYq5IYBdhLWcg3wbgDk#48723190 - https://github.com/potherca-blog/StackOverflow/edit/master/question.13808020.include-an-svg-hosted-on-github-in-markdown/readme.md
如果您需要上传一些图片用于文档,一个好的方法是使用git-lfs。假设您已经安装了git-lfs,请按照以下步骤操作:
Intialize git lfs for your each image type:
git lfs *.png
git lfs *.svg
git lfs *.gif
git lfs *.jpg
git lfs *.jpeg
Create a folder that will be used as image location eg. doc
. On GNU/Linux and Unix based systems this can be done via:
cd project_folder
mkdir doc
git add doc
Copy paste any images into doc folder. Afterwards add them via git add
command.
Commit and push.
The images are publicly available in the following url:
https://media.githubusercontent.com/media/^github_username^/^repo^/^branch^/^image_location in the repo^
在以下内容中:
* ^github_username^
是Github用户名(您可以在个人资料页面找到)
* ^repo_name^
是存储库名称
* ^branch^
是存储图像的存储库分支
* ^image_location in the repo^
是包括存储图像的文件夹的位置。
此外,您可以先上传图像,然后访问您项目的Github页面上的位置,并浏览直到找到图像,然后按下下载
按钮,然后从浏览器地址栏复制粘贴URL。
请参考我的项目中的此处。
然后,您可以使用上述Markdown语法包含它们的URL:
![some alternate text that describes the image](^github generated url from git lfs^)
例如:假设我们使用这张照片,然后你可以使用Markdown语法:
![In what order to compile the files](https://media.githubusercontent.com/media/pc-magas/myFirstEnclave/master/doc/SGX%20Compile%20workflow.png)