Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dpi in include_graphics is not used for docx output #2385

Open
cderv opened this issue Dec 6, 2024 · 1 comment
Open

dpi in include_graphics is not used for docx output #2385

cderv opened this issue Dec 6, 2024 · 1 comment
Labels
feature Feature requests

Comments

@cderv
Copy link
Collaborator

cderv commented Dec 6, 2024

knitr/R/plot.R

Lines 502 to 506 in 4510c09

if (is_latex_output()) {
xfun::decimal_dot(paste0(round(w / dpi, 2), 'in'))
} else if (is_html_output()) {
round(w / (dpi / 96))
}

It seems we don't use dpi calculation for width for other than latex or html.

This is used here to set the out.width

knitr/R/output.R

Lines 610 to 611 in 4510c09

if (is.null(options[['out.width']]))
options['out.width'] = list(raster_dpi_width(x[i], dpi))

---
title: Test
output: word_document
---

```{r}
knitr::include_graphics("pyramide_age_qdl_2.jpeg", dpi = 192)
```

With this file pyramide_age_qdl_2.jpeg

It gives this markdown with no width

![](pyramide_age_qdl_2.jpeg)

setting out.width=500 for example will lead to

![](pyramide_age_qdl_2.jpeg){width=500}

which works in Pandoc thanks to link_attributes extension

For office document we use hook_plot_md_pandoc

knitr/R/hooks-md.R

Lines 16 to 26 in 4510c09

if (office_output) {
if (options$fig.align != 'default') {
warn_options_unsupported('fig.align', to)
options$fig.align = 'default'
}
if (!is.null(options$fig.alt)) {
warn_options_unsupported('fig.alt', to)
options$fig.alt = NULL
}
return(hook_plot_md_pandoc(x, options))
}

Which support width

knitr/R/hooks-md.R

Lines 118 to 135 in 4510c09

hook_plot_md_pandoc = function(x, options) {
if (options$fig.show == 'animate') return(hook_plot_html(x, options))
base = opts_knit$get('base.url') %n% ''
cap = .img.cap(options)
at = paste(
c(
sprintf('width=%s', options[['out.width']]),
sprintf('height=%s', options[['out.height']]),
options[['out.extra']]
),
collapse = ' '
)
if (at != '') at = paste0('{', at, '}')
sprintf('![%s](%s%s)%s', cap, base, .upload.url(x), at)
}

Maybe we should support this ?

@cderv cderv added the feature Feature requests label Dec 6, 2024
@yihui
Copy link
Owner

yihui commented Dec 6, 2024

Yes, I think so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Feature requests
Projects
None yet
Development

No branches or pull requests

2 participants