library(magick)
tmp_dir <- file.path(tempdir(), "spectrakit_imgs")
dir.create(tmp_dir, showWarnings = FALSE)
# Create and save img1
img1 <- image_blank(100, 100, "white")
img1 <- image_draw(img1)
symbols(50, 50, circles = 30, inches = FALSE, add = TRUE, bg = "red")
dev.off()
img1_path <- file.path(tmp_dir, "img1.png")
image_write(img1, img1_path)
# Create and save img2
img2 <- image_blank(100, 100, "white")
img2 <- image_draw(img2)
rect(20, 20, 80, 80, col = "blue", border = NA)
dev.off()
img2_path <- file.path(tmp_dir, "img2.png")
image_write(img2, img2_path)
# Create composite
makeComposite(
folder = tmp_dir,
custom_order = c("img1.png", "img2.png"),
rows = 1,
cols = 2,
labels = list(c("Red Circle", "Blue Rectangle")),
label_settings = list(
list(size = 5, font = "Arial", color = "black", boxcolor = "white",
gravity = "northwest", location = "+10+10", weight = 400)
),
resize_mode = "none",
desired_width = 10,
width_unit = "cm",
ppi = 300,
output_format = "png",
output_folder = tmp_dir
)
Run the code above in your browser using DataLab