9

I'm trying to display an image on my readme.md file on my git repo. I've done this before in my other repos, but for some reason this doesn't work this time.

Currently my code produces the following in the readme file:

enter image description here

I tried:

![Model](path_to_img.pdf)

Which just makes the link open the folder where the image is and show it

I also tried

![Model](link_address_to_image)

Which does the same thing.

I also tried

![Model](path_to_img.pdf?raw=true)

Which makes the link download the image

Manfred
  • 2,269
  • 1
  • 5
  • 14
Penguin
  • 1,923
  • 3
  • 21
  • 51
  • Your link is likely wrong because you need to specify link to raw image. make sure that link works in your browser outside github by copy\pasting it into address bar, web browser should display the image only and nothing else, if yes that's the link for markdown. – metablaster Aug 13 '21 at 19:04
  • Links work just fine – Penguin Aug 13 '21 at 19:06

2 Answers2

17

That display means you aren't linking to the file path. Unfortunately github is really finicky about how it loads images in readme's and you have to use their domain specifically for serving static content. If your image is part of your repo you need to access the file via the raw.githubusercontent.com subdomain specifically the pattern is https://raw.githubusercontent.com/<username>/<repo name>/<branch>/<path to file>.

For example on this project since the homepage image is in ./.github/logo.png and on the master branch of https://github.com/Descent098/ezcv I had to do:

![ezcv logo](https://raw.githubusercontent.com/Descent098/ezcv/master/.github/logo.png)

Edit

Looking at your post I just noticed you have a .pdf file not a .png. PDF's can't be loaded using the inline image syntax, since they aren't inline images. There is a pseudo-solution here, but there's no real clean way to do it otherwise.

Kieran Wood
  • 1,297
  • 8
  • 15
  • 2
    Good catch. I didn't realized that about the PDF file. Changed it to png and it worked! Thanks – Penguin Aug 13 '21 at 19:27
0

  1. upload your picture or file to github.
  2. open that file in github and copy its link.
  3. open Readme.md file and type ![Model](Paste_link_here)
  4. enjoy!
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103