Description Usage Arguments Details Value See Also Examples
Add an external image into a document object
1 2 3 4 5 6 7 8 9 |
doc |
document object |
filename |
|
... |
further arguments passed to other methods |
bookmark |
a character value ; id of the Word bookmark to replace by the image. optional. if missing, image is added at the end of the document. |
par.properties |
paragraph formatting properties of the paragraph that contains images.
An object of class |
width |
image width in inches |
height |
image height in inches |
offx |
optional, x position of the shape (top left position of the bounding box) in inches. See details. |
offy |
optional, y position of the shape (top left position of the bounding box) in inches See details. |
Arguments width
and height
can be defined with functions
png::readPNG
, jpeg::readJPEG
or bmp::read.bmp
.
When document object is a pptx
, width and height are not mandatory.
By default, image is added to the next free 'content' shape of the current slide.
See slide.layouts.pptx
to view the slide layout.
If arguments offx and offy are missing, position is defined as
the position of the next available shape of the slide. This
dimensions can be defined in the layout of the PowerPoint template used to create
the pptx
object.
a document object
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | # get rlogo
img.file <- file.path( Sys.getenv("R_HOME"), "doc", "html", "logo.jpg" )
# tests to use later
has_img <- file.exists( img.file )
has_jpeg <- requireNamespace("jpeg", quietly = TRUE)
has_wmf <- exists("win.metafile")
is_sunos <- tolower(Sys.info()[["sysname"]]) == "sunos"
# create a wmf file if possible
if( has_wmf ){
win.metafile(filename = "image.wmf", width = 5, height = 5 )
barplot( 1:6, col = 2:7)
dev.off()
}
# Image example for MS Word -------
doc <- docx()
if( has_img && has_jpeg ){
dims <- attr( jpeg::readJPEG(img.file), "dim" )
doc <- addImage(doc, img.file, width = dims[2]/72,
height = dims[1]/72)
}
if( has_wmf ){
doc <- addImage(doc, "image.wmf", width = 5, height = 5 )
}
writeDoc( doc, file = "ex_add_image.docx" )
# Image example for MS PowerPoint -------
if( !is_sunos ){
doc <- pptx()
if( has_img && has_jpeg ){
doc <- addSlide( doc, "Title and Content" )
dims <- attr( jpeg::readJPEG(img.file), "dim" )
doc <- addImage(doc, img.file, width = dims[2]/72,
height = dims[1]/72)
}
if( has_wmf ){
doc <- addSlide( doc, "Title and Content" )
doc <- addImage(doc, "image.wmf", width = 5, height = 5 )
}
writeDoc( doc, file = "ex_add_image.pptx" )
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.