ropensci / magick

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

Error in magick_image_annotate #322

Open gangcai opened 3 years ago

gangcai commented 3 years ago

>      logo <- image_read("logo:")
     logo <- image_background(logo, 'white')
     image_fill(logo, "pink", point = "+450+400")
     image_fill(logo, "pink", point = "+450+400", fuzz = 25)
     # Add some text to an image
     image_annotate(logo, "This is a test")
# A tibble: 1 x 7
  format width height colorspace matte filesize density
                    
1 GIF      640    480 sRGB       TRUE         0 +72x+72
# A tibble: 1 x 7
  format width height colorspace matte filesize density
                    
1 GIF      640    480 sRGB       TRUE         0 +72x+72
Error in magick_image_annotate(image, text, gravity, location, degrees,  : 
  R: non-conforming drawing primitive definition `text' @ error/draw.c/RenderMVGContent/4469

gangcai commented 3 years ago

> sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-conda-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

Matrix products: default
BLAS/LAPACK: /public/packages/conda/miniconda3/envs/r4-base/lib/libopenblasp-r0.3.15.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] magick_2.7.2       STutility_0.1.0    ggplot2_3.3.3      SeuratObject_4.0.1
[5] Seurat_4.0.2      

loaded via a namespace (and not attached):
  [1] uuid_0.1-4              systemfonts_1.0.2       plyr_1.8.6             
  [4] igraph_1.2.6            lazyeval_0.2.2          sp_1.4-5               
  [7] splines_4.1.0           crosstalk_1.1.1         listenv_0.8.0          
 [10] scattermore_0.7         digest_0.6.27           foreach_1.5.1          
 [13] htmltools_0.5.1.1       viridis_0.6.1           tiff_0.1-8             
 [16] gdata_2.18.0            fansi_0.5.0             magrittr_2.0.1         
 [19] tensor_1.5              cluster_2.1.2           doParallel_1.0.16      
 [22] ROCR_1.0-11             globals_0.14.0          matrixStats_0.59.0     
 [25] gmodels_2.18.1          spatstat.sparse_2.0-0   jpeg_0.1-8.1           
 [28] colorspace_2.0-1        ggrepel_0.9.1           xfun_0.23              
 [31] dplyr_1.0.6             tcltk_4.1.0             crayon_1.4.1           
 [34] jsonlite_1.7.2          spatstat.data_2.1-0     zeallot_0.1.0          
 [37] survival_3.2-11         zoo_1.8-9               iterators_1.0.13       
 [40] glue_1.4.2              polyclip_1.10-0         gtable_0.3.0           
 [43] leiden_0.3.8            future.apply_1.7.0      abind_1.4-5            
 [46] scales_1.1.1            DBI_1.1.1               miniUI_0.1.1.1         
 [49] Rcpp_1.0.6              viridisLite_0.4.0       xtable_1.8-4           
 [52] spData_0.3.8            units_0.7-1             reticulate_1.20        
 [55] spatstat.core_2.1-2     bit_4.0.4               spdep_1.1-8            
 [58] proxy_0.4-25            akima_0.6-2.1           htmlwidgets_1.5.3      
 [61] httr_1.4.2              RColorBrewer_1.1-2      ellipsis_0.3.2         
 [64] ica_1.0-2               pkgconfig_2.0.3         uwot_0.1.10            
 [67] deldir_0.2-10           utf8_1.2.1              tidyselect_1.1.1       
 [70] rlang_0.4.11            manipulateWidget_0.11.0 reshape2_1.4.4         
 [73] later_1.2.0             munsell_0.5.0           tools_4.1.0            
 [76] cli_2.5.0               dbscan_1.1-8            generics_0.1.0         
 [79] ggridges_0.5.3          stringr_1.4.0           fastmap_1.1.0          
 [82] goftest_1.2-2           bit64_4.0.5             knitr_1.33             
 [85] fitdistrplus_1.1-5      rgl_0.106.8             purrr_0.3.4            
 [88] RANN_2.6.1              readbitmap_0.1.5        pbapply_1.4-3          
 [91] future_1.21.0           nlme_3.1-152            mime_0.10              
 [94] ggiraph_0.7.10          rstudioapi_0.13         hdf5r_1.3.3            
 [97] compiler_4.1.0          curl_4.3.1              plotly_4.9.3           
[100] png_0.1-7               e1071_1.7-7             spatstat.utils_2.1-0   
[103] Morpho_2.8              tibble_3.1.2            stringi_1.6.2.9004     
[106] ps_1.6.0                lattice_0.20-44         Matrix_1.3-4           
[109] classInt_0.4-3          shinyjs_2.0.0           vctrs_0.3.8            
[112] pillar_1.6.1            LearnBayes_2.15.1       lifecycle_1.0.0        
[115] spatstat.geom_2.1-0     lmtest_0.9-38           RcppAnnoy_0.0.18       
[118] data.table_1.14.0       cowplot_1.1.1           irlba_2.3.3            
[121] Rvcg_0.19.2             raster_3.4-10           httpuv_1.6.1           
[124] patchwork_1.1.1         colorRamps_2.3          R6_2.5.0               
[127] imager_0.42.8           promises_1.2.0.1        KernSmooth_2.23-20     
[130] gridExtra_2.3           bmp_0.3                 parallelly_1.25.0      
[133] codetools_0.2-18        boot_1.3-28             MASS_7.3-54            
[136] gtools_3.9.2            withr_2.4.2             sctransform_0.3.2      
[139] expm_0.999-6            mgcv_1.8-36             parallel_4.1.0         
[142] grid_4.1.0              rpart_4.1-15            tidyr_1.1.3            
[145] coda_0.19-4             class_7.3-19            Rtsne_0.15             
[148] sf_0.9-8                shiny_1.6.0            
> 

jeroen commented 3 years ago

This usually happens when your system doesn't have fonts / fontconfig. What is your magick_config() ?

gangcai commented 3 years ago
> magick_config()
$version
[1] ‘7.0.11.14’

$modules
[1] FALSE

$cairo
[1] TRUE

$fontconfig
[1] TRUE

$freetype
[1] TRUE

$fftw
[1] TRUE

$ghostscript
[1] FALSE

$heic
[1] FALSE

$jpeg
[1] TRUE

$lcms
[1] FALSE

$libopenjp2
[1] TRUE

$lzma
[1] TRUE

$pangocairo
[1] TRUE

$pango
[1] TRUE

$png
[1] TRUE

$raw
[1] FALSE

$rsvg
[1] TRUE

$tiff
[1] TRUE

$webp
[1] TRUE

$wmf
[1] FALSE

$x11
[1] TRUE

$xml
[1] TRUE

$`zero-configuration`
[1] FALSE

$threads
[1] 1
gangcai commented 3 years ago

A full simple example to show the error:

> library(magick)
Linking to ImageMagick 7.0.11.14
Enabled features: cairo, fontconfig, freetype, fftw, pango, rsvg, webp, x11
Disabled features: ghostscript, heic, lcms, raw
> logo <- image_read("logo:")
> logo
  format width height colorspace matte filesize density
1    GIF   640    480       sRGB FALSE    28576 +72x+72
> image_annotate(logo, "This is a test")
Error in magick_image_annotate(image, text, gravity, location, degrees,  : 
  rsession: non-conforming drawing primitive definition `text' @ error/draw.c/RenderMVGContent/4469
jeroen commented 3 years ago

How did you get this version of imagemagick? On my CentOS7 server, ImageMagick-devel has version 6.9.10.68. It does not show this problem, your example works.

> library(magick)
Linking to ImageMagick 6.9.10.68
Enabled features: cairo, fontconfig, freetype, ghostscript, lcms, pango, rsvg, x11
Disabled features: fftw, heic, raw, webp
Using 8 threads
> image_annotate(logo, "This is a test")
  format width height colorspace matte filesize density
1    GIF   640    480       sRGB  TRUE        0   72x72

Perhaps you need to build ImageMagick with ghostscript support (I see ghostscript is disabled in your case).

gangcai commented 3 years ago

This version of ImageMagick was installed through conda (conda 4.10.1).

imagemagick               7.0.11_14       pl5320hb118871_0    conda-forge
r-base                    4.1.0                h9e01966_1    conda-forge

jeroen commented 3 years ago

OK in that case I am afraid you need to report the bug in conda :/ There seems to be something wrong with their imagemagick. I think they need to enable ghostscript.

tylermorganwall commented 3 years ago

Getting the same error message in my Github Actions package CHECK, both on ubuntu-20.04 (devel) and (release)

https://github.com/tylermorganwall/rayvertex/runs/2808437042

jeroen commented 3 years ago

This happens on ubuntu when rendering text but the gsfonts debian package is not installed. I think this should fix it: https://github.com/rstudio/r-system-requirements/pull/82

ekianjo commented 1 year ago

I am still facing the same issue on Linux (Solus) when trying to do image_annotate. Ghostscript is installed. Any idea how to fix this from R or outside of R?

Linking to ImageMagick 7.1.0.19 Enabled features: cairo, fontconfig, freetype, fftw, ghostscript, heic, lcms, pango, raw, rsvg, webp, x11 Disabled features: Using 6 threads