knitr::opts_chunk$set(out.width = 830, out.height = 415)
[{htmlwidgets}
] bindings for the imgix rendering API.
Use images from the API in your [{shiny}
] apps and [{rmarkdown}
] documents.
This package can be installed directly from github using the [{remotes}
] package
remotes::install_github("r-webutils/imgix")
Images can be defined with the imgx()
function.
You can either enter a full URL or an id from https://pexels.com.
library(imgix) imgix(2339009) imgix("https://images.unsplash.com/photo-1459478309853-2c33a60058e7")
API parameters can be passed directly to imgix()
.
Underscores are automatically converted to hyphens.
imgix(2422497, rot = 30) imgix(1529360, txt = "Enjoy the rain", txt_size = 100, txt_color = "ddd", txt_align = "center,middle", blur = 20)
Use renderImgix()
to include images to your shiny application.
output$imgix <- renderImgix({ imgix_as_widget(imgix(2339009)) })
The sizing must be defined in the corresponding output function imgixOutput()
.
This packages uses three different strategies to render images depending on the context.
The default mode.
The widget is shown using the [{htmlwidgets}
] interface.
Typical usecases are shiny applications and the rstudio viewer pane.
Use imgix_as_widget()
to directly generate the widget object.
widget <- imgix_as_widget(imgix(2339009))
The image is rendered to an html tag using the [{htmltools}
] package.
The htmltools::as.tag()
generic is implemented and returns an <img>
tag.
This means that imgix
objects can be embedded into tagList
s and other ui definitions that are built with the [{htmltools}
] package.
htmltools::div( imgix(2745224, mask = "ellipse", width = 400, height = 400), imgix('https://images.pexels.com/photos/45848/kumamoto-japan-aso-cloud-45848.jpeg', mask = "ellipse", width = 400, height = 400) )
This mode is currently used for all html-based rmarkdown formats.
The image is downloaded to a local image and referenced via a local path.
For LaTeX-based rmarkdown formats.
To directly download an image, use imgix_download()
imgix_download(imgix(2339009), file = "awesome_picture.jpeg")
imgix_palette()
allows you to extract the most dominant colors from an image.
imgix_palette(2339009)
To get metadata about an image, use imgix_meta()
imgix_meta(2422497)
The rendering API exposes a lot of parameters that can be used to modify images.
All parameters to imgix()
are directly sent as query parameters to the API.
See https://docs.imgix.com/apis/rendering for the full API documentation.
imgix('https://ix-www.imgix.net/solutions/kingfisher.jpg', rect = '2100,600,1800,900') imgix('https://assets.imgix.net/trim-ex4.jpg', monochrome = 787878) imgix("https://images.unsplash.com/photo-1523712999610-f77fbcfc3843", duotone = "000080,FA8072") imgix(1048273, fit = "clip")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.