# How to add images to the README The contents of the `README.md` file may be presented in various places: * Project homepage on GitHub * Project documentation (if using Sphinx build) * PyPI (if publishing there) This places some limitations on including relative content as PyPI is only provided with the content directly in `README.md` and not the surrounding resources. Additionally the Sphinx build uses the `docs` directory as the root of the build meaning that included content is relative to that path. A reference link in Markdown syntax can be used to allow images to be included such that a fixed image URL is used in the `README.md` itself which can be overridden to a relative URL for the Sphinx build. This satisfies the three use cases above. Example of Markdown reference link: ```markdown ![Image alt text][reference] ``` with the `reference` defined (potentially elsewhere) as: ```markdown [reference]: https://mydomain.com/myimage.png ``` ## Example: Image Reference This example shows how to include an image (local to the repository) in the `README.md` such that it will render in all three places mentioned above. In the `README.md` a reference image link is placed at the location the image should be rendered: ```markdown ![my example image][blueapi] ``` at the bottom of the `README.md`, link to a `raw.githubusercontent.com` URL. This is placed below a comment: ```markdown [blueapi]: https://raw.githubusercontent.com/DiamondLightSource/blueapi/main/docs/images/blueapi.png ``` The absolute URL is used to allow PyPI to render the image. If PyPI is not required a relative URL can be used which will work for GitHub rendering. The `README.md` content is included in the Sphinx build (for example `index.md`) but will stop when it reaches the comment: ````markdown ```{include} ../README.md :end-before: