magick icon indicating copy to clipboard operation
magick copied to clipboard

rendering images from pdf fails on centOS

Open julou opened this issue 6 years ago • 10 comments

Hi, I'm trying to read and write pdfs on our cluster where magick is installed with a limited set of features:

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

Unfortunately plot((magick::image_read_pdf("myfig.pdf"))) returns the following error which doesn't happen on macOS:

Error in magick_image_write_frame(image, format = format, i = i) : 
  Dimensions do not add up, 'rgba' may not be a raw format

From feedback I got already (https://github.com/wilkelab/cowplot/issues/114), it sounds like the problem might be that Ghostscript isn't enabled. Unfortunately, I couldn't figure out how to use enable it… I installed the package from source and gs is available from the command line (though with a warning):

> gs
gs: /scicore/soft/apps/LibTIFF/4.0.4-goolf-1.7.20/lib/libtiff.so.5: no version information available (required by /usr/lib64/libgs.so.9)
GPL Ghostscript 9.07 (2013-02-14)
Copyright (C) 2012 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.

Thank you in advance for your help.

julou avatar Nov 13 '18 08:11 julou

Ghostscript is only used for image_read(). If you use image_read_pdf() magick calls out to the pdftools package (which uses libpoppler).

jeroen avatar Nov 13 '18 09:11 jeroen

thanks, this helps: the problem is not in reading but in displaying:

> img <- magick::image_read_pdf("myfig.pdf")
> img
# A tibble: 1 x 7
  format width height colorspace matte filesize density
  <chr>  <int>  <int> <chr>      <lgl>    <int> <chr>  
1 PNG      510   1246 sRGB       TRUE         0 72x72  
> class(img)
[1] "magick-image"

however plotting fails:

> plot(img)
Error in magick_image_write_frame(image, format = format, i = i) : 
  Dimensions do not add up, 'rgba' may not be a raw format

So far I dont understand wether this is expected given my magick config, and if yes how to change it so that plotting works. Thanks

julou avatar Nov 13 '18 09:11 julou

Are you running the latest version of magick?

jeroen avatar Nov 13 '18 09:11 jeroen

Instead of displaying what happens if you write the image:

image_write(img, "test.png", format = "png")

jeroen avatar Nov 13 '18 09:11 jeroen

image_write(img, "test.png", format = "png") works fine!

Indeed I'm using 6.9.3 (because it's always cumbersome to get packages updated on clusters); is it expected to break things? if I need to update is it ok to get the last stable version or do I need the dev as stated on the package readme?

julou avatar Nov 13 '18 09:11 julou

I mean what version of the magick R package do you use? Can you show sessionInfo()? ImageMagick 6.9.3 should be fine.

jeroen avatar Nov 13 '18 10:11 jeroen

sessionInfo() reports magick_2.0 I just reinstalled from CRAN today

julou avatar Nov 13 '18 10:11 julou

OK so that's fine. Can you give some code or file so I can test the issue myself? Maybe it's a bug.

jeroen avatar Nov 13 '18 10:11 jeroen

Also can you show me the version of pdftools and pdftools::poppler_config()

jeroen avatar Nov 13 '18 10:11 jeroen

> pdftools::poppler_config()
$version
[1] "0.63.0"

$can_render
[1] TRUE

$supported_image_formats
[1] "png"  "jpeg" "jpg"  "tiff" "pnm" 

It seems that the problem comes from the size of the canvas/artboard vs text elements?!? I couldn't nail down what exactly hence I attach 2 pdfs which are very similar but one fails and the other not: test_fails.pdf test_ok.pdf

julou avatar Nov 13 '18 13:11 julou