ropensci / magick

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

non-english is broken #119

Open jeonghyunwoo opened 6 years ago

jeonghyunwoo commented 6 years ago

I made ggplot with label written by Korean character. ggplot shows Korean character labels well. but the labels are changed into '??' with image_graph. it seems like encoding problem. can I change the encoding in image_graph?

jeroen commented 6 years ago

Can you please include example code so we can see the problem.

statkclee commented 6 years ago

I had a similar problem when using image_annotate

broken image

# 0. 환경설정 ------
library(tidyverse)
library(magick)

# options(encoding="utf-8")

# 1. 이미지 라벨 ------

smpl_img <- image_read("http://image.chosun.com/sitedata/image/201704/10/2017041001676_1.jpg")

image_annotate(smpl_img, "Clear Blue Sky", size = 70, location = "+50+200", color = "green")

image_annotate(smpl_img, url_encode("청명한 봄하늘"), size = 70, location = "+50+200", color = "green")

> sessionInfo()
R version 3.5.0 (2018-04-23)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

Matrix products: default

locale:
[1] LC_COLLATE=Korean_Korea.949  LC_CTYPE=Korean_Korea.949    LC_MONETARY=Korean_Korea.949
[4] LC_NUMERIC=C                 LC_TIME=Korean_Korea.949    

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

other attached packages:
 [1] urltools_1.7.0  magick_1.8      forcats_0.3.0   stringr_1.3.0   dplyr_0.7.4     purrr_0.2.4    
 [7] readr_1.1.1     tidyr_0.8.0     tibble_1.4.2    ggplot2_2.2.1   tidyverse_1.2.1

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.16     cellranger_1.1.0 pillar_1.2.2     compiler_3.5.0   plyr_1.8.4      
 [6] bindr_0.1.1      tools_3.5.0      lubridate_1.7.4  jsonlite_1.5     nlme_3.1-137    
[11] gtable_0.2.0     lattice_0.20-35  pkgconfig_2.0.1  rlang_0.2.0      psych_1.8.4     
[16] cli_1.0.0        rstudioapi_0.7   curl_3.2         yaml_2.1.19      parallel_3.5.0  
[21] haven_1.1.1      bindrcpp_0.2.2   knitr_1.20       xml2_1.2.0       httr_1.3.1      
[26] hms_0.4.2        triebeard_0.3.0  grid_3.5.0       glue_1.2.0       R6_2.2.2        
[31] readxl_1.1.0     foreign_0.8-70   modelr_0.1.1     reshape2_1.4.3   magrittr_1.5    
[36] scales_0.5.0     rvest_0.3.2      assertthat_0.2.0 mnormt_1.5-5     colorspace_1.3-2
[41] stringi_1.2.2    lazyeval_0.2.1   munsell_0.4.3    broom_0.4.4      crayon_1.3.4    
dmi3kno commented 5 years ago

I think magick works perfectly fine. You just need to indicate "CJK-aware" font installed on your computer. url_encode() is designed for something entirely different. Don't expect it to ever work:

image_annotate(smpl_img, "청명한 봄하늘", size = 70, 
               location = "+50+200", color = "green", font = "Noto Sans CJK SC")

preview

I figured this out by pasting your text into LibreOffice and it immediately suggested the valid font. This might not be as simple on Windows, I realize, but the problem is definitely not with magick. Please, see if you can reproduce and, if successful, please, close the issue.