简体   繁体   English

使用 Markdown 在 GitHub 的 wiki 中调整图像大小

[英]Resize image in the wiki of GitHub using Markdown

I'm writing a wiki page on GitHub, and I'm using Markdown.我正在写一个关于 GitHub 的 wiki 页面,我正在使用 Markdown。

My problem is that I'm putting a large image (this image is in its own repository) and I need resize it.我的问题是我正在放置一个大图像(该图像在它自己的存储库中),我需要调整它的大小。

I have tried different solutions, but they do not work:我尝试了不同的解决方案,但它们不起作用:

![image](http://url.to/image.png "Title" {width=40px height=400px})

![image](http://url.to/image.png = 250x250)

![image](http://url.to/image.png = 250x)

[[http://url.to/image.png = 250x]]

Is there a way to get it?有没有办法得到它?

It is preferable without HTML.最好没有 HTML。

Updated:更新:

Markdown syntax for images (external/internal):图像的 Markdown 语法(外部/内部):

![test](https://github.com/favicon.ico)

HTML code for sizing images (internal/external):用于调整图像大小的HTML 代码(内部/外部):

<img src="https://github.com/favicon.ico" width="48">

Example:例子:

测试


Old Answer:旧答案:

This should work:这应该有效:

[[ http://url.to/image.png | [[ http://url.to/image.png | height = 100px ]] 高度 = 100 像素]]

Source: https://guides.github.com/features/mastering-markdown/来源: https : //guides.github.com/features/mastering-markdown/

On GitHub, you can use HTML directly instead of Markdown:在 GitHub 上,你可以直接使用 HTML 代替 Markdown:

<a href="url"><img src="http://url.to/image.png" align="left" height="48" width="48" ></a>

This should make it.这应该可以。

Almost 5 years after only the direct HTML formatting works for images on GitHub and other markdown options still prevent images from loading when specifying some custom sizes even with the wrong dimensions.大约 5 年后,GitHub 上的图像仅使用直接 HTML 格式,而其他降价选项仍然会在指定某些自定义尺寸时阻止图像加载,即使尺寸错误。 I prefer to specify the desired width and get the height calculated automatically, for example,我更喜欢指定所需的宽度并自动计算高度,例如,

 <img src="https://github.com/your_image.png" alt="Your image title" width="250"/>

I have used methods described above.我已经使用了上述方法。 Now I am using the method which is a way similiar but more simple to me.现在我使用的方法与我相似但更简单。

  1. First create add README.md file to your project.首先创建将 README.md 文件添加到您的项目。
  2. Then upload screenshoots or whatever description images needed to your project main directory.然后将屏幕截图或所需的任何描述图像上传到您的项目主目录。
  3. After uploading image Assets use html to refer these assets directly without using link like below上传图片资源后,使用 html 直接引用这些资源,无需使用如下链接

Like this:像这样:

<img src="icon.jpg" width="324" height="324">

<p align="center">
  <img src="screen1.png" width="256" height="455">
  <img src="screen2.png" width="256" height="455">
  <img src="screen3.png" width="256" height="455">
</p>

On above example I have used paragraph to align images side by side.在上面的例子中,我使用段落来并排对齐图像。 If you are going to use single image just use the code as below如果您打算使用单个图像,请使用以下代码

<img src="icon.jpg" width="324" height="324">

Have a nice day!祝你今天过得愉快!

GitHub Pages now uses kramdown as its markdown engine so you can use the following syntax: GitHub Pages现在使用kramdown作为其降价引擎,因此您可以使用以下语法:

Here is an inline ![smiley](smiley.png){:height="36px" width="36px"}.

http://kramdown.gettalong.org/syntax.html#images http://kramdown.gettalong.org/syntax.html#images

I haven't tested it on GitHub wiki though.我还没有在 GitHub wiki 上测试过它。

Resize by Percentage width=50% height=50% .按百分比调整大小width=50% height=50% Example:例子:

<img src="https://user-images.githubusercontent.com/16319829/81180309-2b51f000-8fee-11ea-8a78-ddfe8c3412a7.png" width=50% height=50%>

Resize by Pixels width="150" height="280" .按像素调整大小width="150" height="280" Example:例子:

<img src="https://user-images.githubusercontent.com/16319829/81180309-2b51f000-8fee-11ea-8a78-ddfe8c3412a7.png" width="150" height="280">

Some tips一些技巧

  • To get a githubusercontent link for an image, drag and drop the image into any issue, and copy/paste the url from the code that is automatically generated.要获取图像的 githubusercontent 链接,请将图像拖放到任何问题中,然后从自动生成的代码中复制/粘贴 url。 Example code: ![image](https://user-images.githubusercontent.com/16319829/81180309-2b51f000-8fee-11ea-8a78-ddfe8c3412a7.png)示例代码: ![image](https://user-images.githubusercontent.com/16319829/81180309-2b51f000-8fee-11ea-8a78-ddfe8c3412a7.png)

  • There is no way to change the size of an image if the markdown format is of the form []() - so stop looking right now!如果 Markdown 格式是[]()形式,无法更改图像的大小- 所以现在停止查看! - you must use <img> instead - 你必须使用<img>代替

  • Another useful summary of conventions that do and don't work here 在这里起作用和不起作用的约定的另一个有用的总结

  • All of the above is from here以上全部来自这里

This addresses the different question, how to get images in gist (as opposed to github) markdown in the first place ?这解决了不同的问题,首先如何在 gist(而不是 github)降价中获取图像?


In December 2015, it seems that only links to files on github.com or cloud.githubusercontent.com or the like work. 2015 年 12 月,似乎只能链接到github.comcloud.githubusercontent.com或类似文件上的文件。 Steps that worked for me in a gist: 在要点中对我有用的步骤:

  1. Make a gist, say Mygist.md (and optionally more files)做一个要点,比如Mygist.md (和可选的更多文件)
  2. Go to the "Write Comment" box at the end转到最后的“写评论”框
  3. Click "Attach files ... by selecting them";单击“附加文件...通过选择它们”; select your local image file选择您的本地图像文件
  4. GitHub echos a long long string where it put the image, eg ![khan-lasso-squared]( https://cloud.githubusercontent.com/assets/1280390/12011119/596fdca4-acc2-11e5-84d0-4878164e04bb.png ) GitHub 在放置图像的位置回显一个长字符串,例如 ![khan-lasso-squared]( https://cloud.githubusercontent.com/assets/1280390/12011119/596fdca4-acc2-11e5-84d0-4878164e04bb.png )
  5. Cut-paste that by hand into your Mygist.md .手动将其剪切粘贴到Mygist.md

But: GitHub people may change this behavior tomorrow, without documenting it.但是:GitHub 人员明天可能会改变这种行为,而无需对其进行记录。

You can tried to put the image into table of markdown, like this:您可以尝试将图像放入 markdown 的表中,如下所示:

| ![Kiku](docs/snapshot/home.jpeg)        | ![Kiku](docs/snapshot/sub.jpeg) |
| --------------------------------------- | --------------------------------------- |
| ![Kiku](docs/snapshot/user-center.jpeg) |                                         |

it will make the image layout like grid, but it could not custom for each single image size.它将使图像布局像网格一样,但它不能为每个图像大小自定义。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM