【问题标题】:Inserting external image into PowerPoint with officer without changing image dimensions使用官员将外部图像插入 PowerPoint 而不更改图像尺寸
【发布时间】:2021-08-28 15:04:09
【问题描述】:

是否可以在不更改图像尺寸的情况下使用officer 将外部图像插入到 Powerpoint 中?

这是我现在拥有的代码,其中xrpptx 对象:

library(officer)
image_url <- "https://upload.wikimedia.org/wikipedia/commons/thumb/e/e7/Instagram_logo_2016.svg/768px-Instagram_logo_2016.svg.png"
 t_file <- tempfile(pattern = "logo_", fileext = ".png")
 download.file(image_url, destfile = t_file)
 x <- x %>%
    ph_with(value = external_img(t_file), location = ph_location(left = 9.4, top = 4.6))

这会将图像的尺寸更改为 4x3 英寸(ph_location() 的默认值)。

我知道您可以使用外部 R 包获取图像元数据,然后将其传递给函数,以便使用实际图像尺寸,但我不想添加任何更多外部 R 包依赖项。

【问题讨论】:

    标签: r officer


    【解决方案1】:

    您始终可以在 external_img 函数中指定图像尺寸。我假设你知道你想要什么尺寸,所以说你的尺寸是宽度 = 9,高度 = 5 它看起来像这样:

        library(officer)
    image_url <- "https://upload.wikimedia.org/wikipedia/commons/thumb/e/e7/Instagram_logo_2016.svg/768px-Instagram_logo_2016.svg.png"
     t_file <- tempfile(pattern = "logo_", fileext = ".png")
     download.file(image_url, destfile = t_file)
     x <- x %>%
    #specify height and width
        ph_with(value = external_img(t_file, width = 9, height = 5), location = ph_location(left = 9.4, top = 4.6))
    

    希望对您有所帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-26
      • 1970-01-01
      • 2017-02-07
      • 1970-01-01
      • 2018-01-23
      • 2016-02-26
      • 2011-06-15
      相关资源
      最近更新 更多