How do I display local image in markdown?

后端 未结 18 1874
孤独总比滥情好
孤独总比滥情好 2020-12-12 14:00

Does anyone know how to display a local image in markdown? I don\'t want to setup a webserver for that.

I try the following in markdown, but it doesn\'t work:

相关标签:
18条回答
  • 2020-12-12 14:34

    You may find following the syntax similar to reference links in markdown handy, especially when you have a text with many displays of the same image:

    ![optional text description of the image][number]
    
    [number]: URL
    

    For example:

    
    ![][1]
    
    ![This is an optional description][2]
    
    
    
    
    [1]: /home/jerzy/ComputerScience/Parole/Screenshot_2020-10-13_11-53-29.png
    [2]: /home/jerzy/ComputerScience/Parole/Screenshot_2020-10-13_11-53-30.png
    
    
    0 讨论(0)
  • 2020-12-12 14:35

    The best solution is to provide a path relative to the folder where the md document is located.

    Probably a browser is in trouble when it tries to resolve the absolute path of a local file. That can be solved by accessing the file trough a webserver, but even in that situation, the image path has to be right.

    Having a folder at the same level of the document, containing all the images, is the cleanest and safest solution. It will load on GitHub, local, local webserver.

    images_folder/img.jpg  < works
    
    
    /images_folder/img.jpg  < this will work on webserver's only (please read the note!)
    

    Using the absolute path, the image will be accessible only with a url like this: http://hostname.doesntmatter/image_folder/img.jpg

    0 讨论(0)
  • 2020-12-12 14:35

    Edited:

    Working for me ( for local image )

    ![system schema](doc/systemDiagram.jpg)
    
     tree
     ├── doc
         └── jobsSystemSchema.jpg
     ├── README.md
    

    markdown file README.md is at the same level as doc directory.

    In your case ,your markdown file should be at the same level as the directory files.

    Working for me (absolute url with raw path)

    ![system schema](https://server/group/jobs/raw/master/doc/systemDiagram.jpg)
    

    NOT working for me (url with blob path)

    ![system schema](https://server/group/jobs/blob/master/doc/systemDiagram.jpg)
    
    0 讨论(0)
  • 2020-12-12 14:38

    Another possibility for not displayed local image is unintentional indent of the image reference - spaces before ![alt text](file).

    This makes it 'code block' instead of 'image inclusion'. Just remove the leading spaces.

    0 讨论(0)
  • 2020-12-12 14:39

    No need to set up a web server

    I tried uploading my local image in the comment section of the gist and simply copied and pasted the generated URL. Worked for me

    0 讨论(0)
  • 2020-12-12 14:43

    Either put the image in the same folder as the markdown file or use a relative path to the image.

    0 讨论(0)
提交回复
热议问题