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

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

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

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


当前回答

这就行了!!

注意标记中的文件名大写,将PNG文件放入根目录,并链接到没有任何路径的文件名:

![Screenshot](screenshot.png)

其他回答

如果您需要上传一些图片用于文档,一个不错的方法是使用git-lfs。假设您已安装git-lfs,请执行以下步骤:

初始化每个图像类型的git-lfs:数字lfs*.png数字lfs*.svg数字lfs*.gifgit-lfs*.jpggit-lfs*.jpeg创建一个将用作图像位置的文件夹,例如doc。在基于GNU/Linux和Unix的系统上,这可以通过以下方式完成:cd项目文件夹mkdir文档git添加文档复制粘贴任何图像到文档文件夹。然后通过gitadd命令添加它们。提交并推送。图片可在以下url中公开获取:https://media.githubusercontent.com/media/^github_username^/^repo^/^branch^/^image_location在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)

基本语法

![myimage-alt-tag](url-to-image)

在这里:

my image alt标记:如果未显示图像,将显示的文本。图像的url:无论您的图像资源是什么。图像的URI

例子:

![stack Overflow](http://lmsotfy.com/so.png)

如下所示:

还有一个选项我还没有看到。您可以简单地在用户或组织下创建另一个名为“资产”的存储库。将您的图像推送到此回购,并从其他回购中引用它们:

![alt text](https://raw.githubusercontent.com/my-org/assets/master/folder/logo.png)

我在我的一次回购中做了这件事,它很适合我。我可以独立于我的代码为我的所有项目版本我的README图像,但仍然将它们保存在一个地方。不需要问题、分支或其他容易错位的工件。

此答案也可在以下位置找到: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上显示打印屏幕,但也在NPM上显示。尽管使用相对路径在Github内部有效,但在Github之外却无法正常工作。基本上,即使我也将项目推到了NPM(它只是使用了相同的readme.md),图像也从未显示。

我尝试了几种方法,最后这对我有用:

![预览](https://raw.githubusercontent.com/username/project/master/image-path/image.png)

我现在可以在NPM或任何其他我可以发布我的包的地方正确地看到我的图像。