tylermorganwall / rayshader

R Package for 2D and 3D mapping and data visualization
https://www.rayshader.com/
2.06k stars 214 forks source link

How to change dpi in render_highquality()? #293

Closed dominicroye closed 11 months ago

dominicroye commented 1 year ago

I am trying to obtain a PNG image with more than 72 dpi. As far as I understand, width and height in render_highquality() define the rgl window in pixels, but what about dpi? I have created 8000 x 8000 px but always with 72 dpi, which is low resolution for printing. I found from another package https://coolbutuseless.github.io/package/devoutrgl/reference/rgldev.html where it is possible for rgl to indicate both width and height in inches and the dpi value.

Thank you

tylermorganwall commented 11 months ago

Hello,

Thank you for your question regarding DPI in images created with rayshader. You are correct that width and height parameters in render_highquality() define the pixel dimensions of the image, and DPI is a separate concept, primarily relevant for printing.

For digital images, DPI can be adjusted without changing the actual pixel data. This adjustment alters how the image is intended to be printed or displayed. If you need to set a specific DPI for printing, you can use the magick package in R to modify the DPI metadata of the PNG file.

Here's an example code snippet:

library(magick)

# Load the image
image <- image_read("path/to/your/image.png")

# Set the desired DPI, e.g., 300
image_write(image, "path/to/your/output_image.png", density = 300)