ropensci / magick

Magic, madness, heaven, sin
https://docs.ropensci.org/magick
Other
462 stars 65 forks source link

Error in image_draw(): "figure margins too large" with very small images (solution proposed) #317

Closed MatteaE closed 1 year ago

MatteaE commented 3 years ago

Offending code (R 3.6.3, magick 2.6.0, ImageMagick 6.9.10.23, Ubuntu 20.04, 1920x1200 resolution):

library(magick)
image_draw(image_blank(30,30))
Error in graphics::plot.new() : figure margins too large

From both console and RStudio. No value of parameter mar passed to image_draw() fixes the issue. Also resizing the plot panel in RStudio has no effect.

Solution (on my system at least): swap two lines in magick:::setup_device(), from

graphics::plot.new()
graphics::par(mar = mar)

to

graphics::par(mar = mar)
graphics::plot.new()

Not sure if this breaks anything else :-)

Balaika commented 1 year ago

This issue still exists with magick version 2.8.0. The MatteaE workaround is still valid.

jeroen commented 1 year ago

Thanks! I committed it now.