The magick
package documentation shows how to make a mosaic of a vector of image objects:
bigdata <- image_read('https://jeroen.github.io/images/bigdata.jpg')
frink <- image_read("https://jeroen.github.io/images/frink.png")
logo <- image_read("https://jeroen.github.io/images/Rlogo.png")
img <- c(bigdata, logo, frink)
image_mosaic(img)
This works great. However, as a result of using purrr::map
with some function which takes an image file name and returns an image, I get a list of image objects, not a vector, and the image_mosaic
will not accept this list.
Reproducible example (this is just a mock example, obviously I need this for more than 3 images!):
read_image_wrapper <- function(url) image_read(url)
urls <- c("https://jeroen.github.io/images/bigdata.jpg", "https://jeroen.github.io/images/frink.png", "https://jeroen.github.io/images/Rlogo.png")
images_list <- purrr::map(urls, read_image_wrapper)
image_mosaic(images_list)
Error: The 'image' argument is not a magick image object.
And unlist
ing won't work.
So I either need to understand how to unlist images_list
in a way which will make it an image object, or change my purrr:map
approach (don't suppose there's a purrr:map_img
, is there?)
If we take a look at what magick
does under the hood — https://github.com/ropensci/magick/blob/master/R/base.R#L58-L60 — we'll see that c()
is really just a call to image_join()
so you can just do image_join(images_list)
to get what you need.