impac | R Documentation |
A simple greedy algorithm tries to pack as many images into a larger image as possible, taking into account transparency, if available (recommended).
impac(
im,
width = 1024,
height = 800,
mask = NULL,
weights = NULL,
preferred = NULL,
max_num_tries = 100,
scales = c(rep(0.5, 2), rep(0.25, 4), rep(0.15, 8)),
scale_fun = function(s, i, c) { if (c < (i * 0.5)) { mscale <- min(s)
c(s, rep(mscale/2, floor(1/mscale))) } else { scales } },
max_images = 1000,
min_scale = 0.05,
bg = "transparent",
show_every = 25,
progress = TRUE,
start_image = NULL,
...
)
im |
Can be either a character vector of image
file names (format must be compatible with |
width |
Width in pixels of produced image |
height |
Height in pixels of produced image |
mask |
An optional masking image. |
weights |
Vector of Weights to apply to each image. Higher weighted images will be packed first and so will tend to be larger. This vector will be recycled. |
preferred |
An alternate way to specify images to pack first, as
a character vector of names or file names (only works if |
max_num_tries |
Maximum number of times to try packing an image onto the canvas before giving up. |
scales |
A vector of starting scaling factors to randomly choose from for each image. |
scale_fun |
An function that takes three arguments,
which correspond to the current vector of scaling factors, the current
iteration of the algorithm, and the count of the number of packed images
so far, respectively (e.g. |
max_images |
The maximum number of images to pack before stopping. |
min_scale |
The minimum scale factor to use. If the algorithm
generates a scale factor this small (via |
bg |
The background colour for the campus, default: "transparent" |
show_every |
Show the intermediate packed image after every
|
progress |
Should progress be printed as the algorithm runs? |
start_image |
An optional image to start the packing with. If not
|
... |
Further arguments passed on the |
A packed image mosaic, as a imager::cimg
object.
plot(
impac(
function(i) imager::draw_circle(
imager::imfill(500, 500, val = c(0, 0, 0, 0)),
250, 250, radius = runif(1, 150, 250),
color = matrix(grDevices::col2rgb(sample(grDevices::rainbow(100), 1), alpha = TRUE), nrow = 1)
),
width = 400, height = 400,
max_images = 10, bg = "white"
)$image
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.