Skip to content

Commit

Permalink
add support for .jpg format in preview_plot()
Browse files Browse the repository at this point in the history
  • Loading branch information
kadyb authored May 31, 2024
1 parent f10126e commit 70d4e10
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions R/preview-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#'
#' This is a helper function to plot preview assets
#' (e.g. quicklook, thumbnail, rendered_preview).
#' Currently, only png and jpeg formats are supported.
#' Currently, only png, jpeg and jpg formats are supported.
#'
#' @param url image URL to be plotted.
#'
Expand All @@ -12,7 +12,7 @@
preview_plot <- function(url) {
preview_check(url)
img <- preview_read_file(url)
plot(1:10, ty = "n", axes = F, xlab = "", ylab = "")
plot(1:10, type = "n", axes = FALSE, xlab = "", ylab = "")
grid::grid.raster(img)
}

Expand All @@ -39,6 +39,12 @@ preview_check <- function(url) {
"This function requires `jpeg` package. Please, use",
"install.packages('jpeg')."
))
,
jpg = if (!requireNamespace("jpeg", quietly = TRUE))
.error(paste(
"This function requires `jpeg` package. Please, use",
"install.packages('jpeg')."
))
)
}

Expand All @@ -55,7 +61,8 @@ preview_read_file <- function(url) {
preview_switch(
url,
png = png::readPNG(temp_file),
jpeg = jpeg::readJPEG(temp_file)
jpeg = jpeg::readJPEG(temp_file),
jpg = jpeg::readJPEG(temp_file)
)
}

Expand Down

0 comments on commit 70d4e10

Please sign in to comment.