collage icon indicating copy to clipboard operation
collage copied to clipboard

collage multiple png into a single image of higher device size

Open gadepallivs opened this issue 3 years ago • 11 comments

Hi got this issues when trying to install the package. Can you please let m know if this is compatible with R4.02.

gadepallivs avatar Nov 10 '20 20:11 gadepallivs

I don't think this is on CRAN, so you need to do remotes::install_github("ThinkR-open/collage")

jeroen avatar Nov 10 '20 20:11 jeroen

Thank you. I am trying to collage multiple png into a single png of higher size than my default device size. SO question here. I came across this package. Wondering if this is the right package for what I am trying to achieve?

gadepallivs avatar Nov 10 '20 21:11 gadepallivs

Have a look at the image_montage function in the magick package.

jeroen avatar Nov 10 '20 21:11 jeroen

example.zip update: added an example images.

image_files <-
  list.files(
    path = here::here("example"),
    recursive = TRUE,
    pattern = "\\.png$",
    full.names = TRUE
  )
files <-  image_files

img <- magick::image_read(files) %>%
  magick::image_montage(tile = '2',geometry = 'x500+10+10') %>%
  magick::image_convert("jpg") %>%
  magick::image_write(format = ".jpg", path = here::here("test.jpg"),
                      quality = 100)

figured from the documentation that geometry parameter controls the width and height. and the tile controls the column.

# A tibble: 1 x 7
format width height colorspace matte filesize density
<chr>  <int>  <int> <chr>      <lgl>    <int> <chr>  
  1 ""      1290   2080 sRGB       FALSE        0 72x72  
 2 ""      1290   2080 sRGB       FALSE        0 72x72  
  • How to pass arguments for a custom title for the collage image, footer ? Would like to add title, datestamp etc

gadepallivs avatar Nov 12 '20 15:11 gadepallivs

Can you add example images to your script so I can reproduce your issue?

jeroen avatar Nov 12 '20 16:11 jeroen

updated the Q, with an example.zip. Please ignore the image as I just created copies of the same image.

gadepallivs avatar Nov 12 '20 16:11 gadepallivs

The tile controls the column and rows, for example 4x3. See the docs. To overlay text you can use image_annotate()

jeroen avatar Nov 12 '20 20:11 jeroen

Thank you jeroen, the documentation was helpful. When using image_annotate, the text is more over laid on top of the image rather than a centered heading with space around it. Is there any better way to include a title, sub-text, footer etc ?

gadepallivs avatar Nov 12 '20 21:11 gadepallivs

Did you try the location and gravity parameters? If you set gravity = "north" it will be centered at the top.

jeroen avatar Nov 12 '20 21:11 jeroen

yes, I am using

magick::image_annotate("The group A charts",
     size = 75, location = "+000+000" ) . 

Tried the ,gravity = "north", the text is centered but still I see the text is over the y axis

gadepallivs avatar Nov 12 '20 21:11 gadepallivs

If you want to add space around your figure, you can try image_border(). Or you can start with image_blank() to create a canvas and then image_composite() your image on top of it.

But if you just want to combine plots, have you looked at the patchwork package? https://patchwork.data-imaginist.com/

jeroen avatar Nov 12 '20 22:11 jeroen