How to use .ico images in graphics programmatically with / without conversion

How to use .ICOimage files in graphics programmatically with / without conversion?

My question is continued. How to convert .ICO to .PNG? aimed at R, and with the following specific details:

  • I do not ask about methods that include icons in HTML, for example. inside the application shiny(author: RStudio). This, of course, is possible.

  • Can icon files .ICObe used directly based on base-R, ggplot object (author: Hadley Wickham), grid graph (author: Deepayan Sarkar)? And will this approach be reliable for printing output on PDF?

  • How to convert icons ICOto PNGwith Ror without a dedicated library . This method will be careful to handle the size, depth, transparency, and other potentially important properties of the icon image.

The motivation for this is that there are many open source libraries that can be used inside story objects, for example. Insert an image in ggplot2 , Display a custom image as geom_point , Insert an image in ggplot outside the chart area .

In the question I quote above, How to convert .ICO to .PNG? , there are code examples in C#and in Python, but not in R.

+4
source share
2 answers

Now there is a package magickand you no longer need to use system:

library(magick)
path  <- "magic.png" # wherever you want to save
image <- image_read("https://rpubs.com/favicon.ico") # works with local path as well

In Studio R, this prints our image in the graph window; for ico files, it displays various icons available in the file.

image 

Then you can save in the desired format:

image_write(image,path,"png")
file.exists(path)
# [1] TRUE

There really is a cool vignette :

+2
source

Install ImageMagick on your system ( your system is not an R package). Its a set of open source image management and conversion tools.

convert foo.ico foo.png. ICO , foo-1.ico foo-N.ico. convert , ImageMagick.

R, system:

 name = "foo"
 system(paste0("convert ",name,".ico ",name,".png"))

PNG. ( ..) , PNG , , . PNG.

R- ICO ( ), , , , ImageMagick ​​ . .

+2

All Articles