|
1 | 1 | --- |
2 | | -title: (5) Images, videos and documents |
| 2 | +title: Images, videos and documents |
3 | 3 | --- |
| 4 | + |
| 5 | +## Images |
| 6 | + |
| 7 | +You can add images to a Quarto page using Markdown. |
| 8 | +The basic pattern is: |
| 9 | + |
| 10 | +```markdown |
| 11 | + |
| 12 | +``` |
| 13 | + |
| 14 | +In this example, we have an image file called `south_cloisters.jpg` in the `images` folder. The path to the file is: |
| 15 | + |
| 16 | +* `..` meaning "go up one folder". |
| 17 | +* `images` is the folder name. |
| 18 | +* `south_cloisters.jpg` is the file name. |
| 19 | + |
| 20 | +If your image is in the same folder as your `.qmd` file, you could just write the file name. |
| 21 | + |
| 22 | +This shows the image at its default size and alignment: |
| 23 | + |
| 24 | +```markdown |
| 25 | + |
| 26 | +``` |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | +You can control the size of the image with `width`: |
| 31 | + |
| 32 | +TODO: EXPLAIN CURLY BRACES |
| 33 | + |
| 34 | +```markdown |
| 35 | +{width=50%} |
| 36 | +``` |
| 37 | + |
| 38 | +{width=50%} |
| 39 | + |
| 40 | +To add a caption, put text inside the square brackets: |
| 41 | + |
| 42 | +```markdown |
| 43 | + |
| 44 | +``` |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | +We can control alignment using `fig-align`: |
| 49 | + |
| 50 | +```markdown |
| 51 | +{fig-align="center"} |
| 52 | +``` |
| 53 | + |
| 54 | +{fig-align="center"} |
| 55 | + |
| 56 | +Adding `.lightbox` lets people click to see a larger version of the image - helpful when you have detailed figures or diagrams. |
| 57 | + |
| 58 | +```markdown |
| 59 | +{.lightbox} |
| 60 | +``` |
| 61 | + |
| 62 | +{.lightbox} |
| 63 | + |
| 64 | +You can also make your figure a hyperlink: |
| 65 | + |
| 66 | +```markdown |
| 67 | +[](https://medicine.exeter.ac.uk/research/facilities/southcloisters/) |
| 68 | +``` |
| 69 | + |
| 70 | +[](https://medicine.exeter.ac.uk/research/facilities/southcloisters/) |
| 71 | + |
| 72 | +To add alternative text to your image: |
| 73 | + |
| 74 | +```markdown |
| 75 | +{fig-alt="Photograph of South Cloisters on St Lukes Campus"} |
| 76 | +``` |
| 77 | + |
| 78 | +{fig-alt="Photograph of South Cloisters on St Lukes Campus"} |
| 79 | + |
| 80 | +::: {.pale-blue} |
| 81 | + |
| 82 | +**Task**: Open `media.qmd`, see image is provided in images folder |
| 83 | + |
| 84 | +* [ ] Add image at full width |
| 85 | +* [ ] Add it again, 40% width, aligned to right |
| 86 | +* [ ] Add third copy with short caption and alt text. |
| 87 | + |
| 88 | +Render the page and compare how the three images look. |
| 89 | + |
| 90 | +::: |
| 91 | + |
| 92 | +## Videos |
| 93 | + |
| 94 | +You can embed videos (for example, from YouTube) using the `video` shortcode. It will show a video player inside your page. Here is an example: |
| 95 | + |
| 96 | +TODO: EXPLAIN WHAT A SHORTCODE IS |
| 97 | + |
| 98 | +```{.markdown shortcodes="false"} |
| 99 | +{{< video https://youtu.be/BUN0sSa2e9c?si=-o7gu4FGOZS7L2rt >}} |
| 100 | +``` |
| 101 | + |
| 102 | +{{< video https://youtu.be/BUN0sSa2e9c?si=-o7gu4FGOZS7L2rt >}} |
| 103 | + |
| 104 | +::: {.pale-blue} |
| 105 | + |
| 106 | +**Task**: On `media.qmd`: |
| 107 | + |
| 108 | +* [ ] Add a YouTube video to the page - for example: |
| 109 | + |
| 110 | +```{.markdown shortcodes="false"} |
| 111 | +{{< video https://www.youtube.com/watch?v=dQw4w9WgXcQ >}} |
| 112 | +``` |
| 113 | + |
| 114 | +Render the page and check that the video player appears. |
| 115 | + |
| 116 | +::: |
| 117 | + |
| 118 | +## Embed websites |
| 119 | + |
| 120 | +Sometimes you might want to show another website (e.g., news article, uni web page, etc.) inside your page. You can do this using an HTML `<iframe>`. |
| 121 | + |
| 122 | +TODO: beginner friendly explanation of HTML syntax and of iframes |
| 123 | + |
| 124 | +```markdown |
| 125 | +<iframe width="100%" height="500" src="https://quarto.org/" title="Quarto Documentation"></iframe> |
| 126 | +``` |
| 127 | + |
| 128 | +<iframe width="100%" height="500" src="https://quarto.org/" title="Quarto Documentation"></iframe> |
| 129 | + |
| 130 | +::: {.pale-blue} |
| 131 | + |
| 132 | +**Task**: On `media.qmd`: |
| 133 | + |
| 134 | +* [ ] Embed a website of your choice using an `<iframe>`. |
| 135 | +* [ ] Change the `height` to a different value (e.g., `200`) and see how it changes the space used on the page. |
| 136 | + |
| 137 | +::: |
| 138 | + |
| 139 | +::: {.callout-note title="Advanced Extra: Wrapper" collapse="true"} |
| 140 | + |
| 141 | +Sometimes you may want a header above the iframe.... distinguish embedded page from yours... give it more formal... e.g., open in new tab etc... here is an example wrapper adapted from https://github.com/andrewheiss/ath-quarto/blob/main/cv/index.qmd |
| 142 | + |
| 143 | +````markdown |
| 144 | +```{=html} |
| 145 | +<div class="iframe-wrapper"> |
| 146 | + <div class="iframe-header"> |
| 147 | + <span>Website preview:</span> |
| 148 | + <a href="https://quarto.org/" |
| 149 | + target="_blank" rel="noopener"> |
| 150 | + View website in new tab |
| 151 | + </a> |
| 152 | + </div> |
| 153 | +
|
| 154 | + <iframe |
| 155 | + width="100%" |
| 156 | + height="500" |
| 157 | + src="https://quarto.org/" |
| 158 | + title="Quarto Documentation"> |
| 159 | + </iframe> |
| 160 | +</div> |
| 161 | +<br> |
| 162 | +
|
| 163 | +.embed-container { |
| 164 | + position: relative; |
| 165 | + padding-bottom: 129%; |
| 166 | + height: 0; |
| 167 | + overflow: hidden; |
| 168 | + max-width: 100%; |
| 169 | +} |
| 170 | +.embed-container iframe, |
| 171 | +.embed-container object, |
| 172 | +.embed-container embed { |
| 173 | + position: absolute; |
| 174 | + top: 0; |
| 175 | + left: 0; |
| 176 | + width: 100%; |
| 177 | + height: 100%; |
| 178 | +} |
| 179 | +``` |
| 180 | +```` |
| 181 | + |
| 182 | +::: |
| 183 | + |
| 184 | +## PDFs |
| 185 | + |
| 186 | +You can embed a PDF so that it appears inside the page. The simplest way (using raw HTML) is: |
| 187 | + |
| 188 | +```markdown |
| 189 | +<embed src="media/example.pdf" width="100%" height="1000px" /> |
| 190 | +``` |
| 191 | + |
| 192 | +```{=html} |
| 193 | +<embed src="media/example.pdf" width="100%" height="1000px" /> |
| 194 | +``` |
| 195 | + |
| 196 | +::: {.callout-note title="Advanced Extra: Responsive Container" collapse="true"} |
| 197 | + |
| 198 | +If you want more control (for example, a responsive container), you can use CSS: |
| 199 | + |
| 200 | +``` |
| 201 | +.embed-container { |
| 202 | + position: relative; |
| 203 | + padding-bottom: 129%; |
| 204 | + height: 0; |
| 205 | + overflow: hidden; |
| 206 | + max-width: 100%; |
| 207 | +} |
| 208 | +.embed-container iframe, |
| 209 | +.embed-container object, |
| 210 | +.embed-container embed { |
| 211 | + position: absolute; |
| 212 | + top: 0; |
| 213 | + left: 0; |
| 214 | + width: 100%; |
| 215 | + height: 100%; |
| 216 | +} |
| 217 | +``` |
| 218 | + |
| 219 | +::: |
| 220 | + |
| 221 | +::: {.pale-blue} |
| 222 | + |
| 223 | +**Task**: we have provided a pdf namem ... on `media.qmd`: |
| 224 | + |
| 225 | +* [ ] Embed the example PDF. |
| 226 | + |
| 227 | +::: |
0 commit comments