#' Resize an image
#'
#' Decreases the side of an image so it can be used smoothly by other functions.
#' Returns a raster.
#' @param img source of any supported type, see ?convert
#' @param resize resize factor between 0 and 1
#' @param from source format, guessed by default
resize <- function(img,resize,
from = c("auto","raster","url","path",
"array3","matrix","long")){
from <-match.arg(from)
if(from == "auto") from <- guess_format(img)
if(from == "array3"){
img <- convert(resize_arr(img,resize),to="raster")
} else
{
if (from != "marix") img <- convert(img,to="matrix")
img <- as.raster(resize_mat(img,resize))
}
img
}
resize_arr <- function(img,resize){
coords <- lapply(dim(img)[-3],function(x){
n <-round(x*resize)
round(seq(1,x,(x-1)/(n-1)))
})
img <- img[coords[[1]],coords[[2]],]
img
}
resize_matrix <- function(img,resize){
coords <- lapply(dim(img),function(x){
n <-round(x*resize)
round(seq(1,x,(x-1)/(n-1)))
})
img <- img[coords[[1]],coords[[2]]]
img
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.