Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for .jpg format in preview_plot() (fix #161) #162

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading