r-markdownxaringan

How to use image in my computer as a background image in xaringan


I know the following code will make a background image of xaringan slide.

---
class: inverse, left, top
background-image: 
url("")
background-size: contain

But what if the image is not from web but from my computer. In that case, how should I put the link instead of url()?


Solution

  • Simply provide the file path of that image file inside the url().

    ---
    title: "Local Image file on Xaringan"
    output: xaringan::moon_reader
    ---
    
    ## Adding local Image
    
    The process of adding local image file (file from computer) is similar to that
    of images from web. Simply provide the path to that image file in `url()`. For
    example, suppose the jpg file `lights.jpg` is in the working directory. So we 
    can simply reference to it as `url("lights.jpg")`.
    
    ---
    class: title-slide, top, left, inverse
    background-image: url("lights.jpg")
    background-size: cover