RMarkdown 中 jpeg 的图像方向错误

Har*_*son 5 r knitr r-markdown

我正在尝试将图像上传到 RMarkdown html 文档。我一直在使用 include_graphics() 函数从我的工作目录加载 .jpg 文件。

大多数图像上传正确,但有些图像翻转了 90 度。此错误仅发生在肖像图像上。

如果我尝试在块之外在线上传它们,则会发生相同的错误。

我已经在 Windows 资源管理器中打开了这些图像,它们的方向正确。在 MS Paint 或 Google Drive 中打开时,它们也是正确的。有趣的是,如果我将人像 jpeg 转换为 .png 文件,它们就会以正确的纵向显示在 RMarkdown 中。我会接受这个修复,但是 .png 文件会显着增加我的 html 文档的大小,所以我更喜欢使用原始的 .jpg 图像。

```{r setup, include=FALSE}
library(knitr)
knitr::opts_knit$set(root.dir = "C:/Users/Harrison/Documents/Project")
Run Code Online (Sandbox Code Playgroud)

示例图片:https : //upload.wikimedia.org/wikipedia/commons/8/88/Killington_trail.jpg

## in-line example (wrong orientation)
![trail]\(https://upload.wikimedia.org/wikipedia/commons/8/88/Killington_trail.jpg)

## chunk example (after saving the image to working directory folder as "image.jpg")
knitr::include_graphics("image.jpg") # produces same orientation error

# save image.jpg as a png file and try again
knitr::include_graphics("image.png") # produces correct orientation
Run Code Online (Sandbox Code Playgroud)

有没有人处理过这个问题?