Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save a high resolution image with magick in R?

Tags:

r

magick

I would like to create a high resolution “montage” of 3 by 3 using the magick package.

library(magick)
#> Linking to ImageMagick 6.9.7.4
#> Enabled features: fontconfig, freetype, fftw, lcms, pango, x11
#> Disabled features: cairo, ghostscript, rsvg, webp

# Read the image and resize it
frink <- image_read("https://jeroen.github.io/images/frink.png")
frink <- image_resize(frink, "100x")

# Create 1 column with 3 rows
col <- image_append(rep(frink, 3), stack = TRUE)

# "Combine" 3 columns
i <- image_append(c(col, col, col))

i

So my question is how can I save it to a high-resolution png (e.g., 300 DPI)? I was thinking to use image_write(), but apparently I can not set the resolution I want there.

# This is not working
# image_write(i, tempfile(), res = 300)

Created on 2019-05-09 by the reprex package (v0.2.1)

like image 608
Philippe Massicotte Avatar asked Sep 18 '25 06:09

Philippe Massicotte


1 Answers

I had the same problem but found the solution in the magick vignett https://docs.ropensci.org/magick/articles/intro.html#read-and-write

image_write(i, path = "final.png", format = "png")
like image 119
Dr. Flow Avatar answered Sep 20 '25 19:09

Dr. Flow