Skip to content

Instantly share code, notes, and snippets.

@dmi3kno
Last active February 4, 2020 10:16
Show Gist options
  • Save dmi3kno/da6323a063ea736572bfacb7be21b165 to your computer and use it in GitHub Desktop.
Save dmi3kno/da6323a063ea736572bfacb7be21b165 to your computer and use it in GitHub Desktop.
Making magick logo
library(magick)
# remotes::install_github("dmi3kno/bunny")
library(bunny)
# this is for editing svg removing all tags of type <text>
library(xml2)
im_path <- "https://upload.wikimedia.org/wikipedia/commons/9/9a/ImageMagick_logo.svg"
a <- xml2::read_xml(im_path)
a1 <- a %>%
xml2::xml_find_all("//svg:text") %>%
xml2::xml_remove()
rm(a1)
gc()
a %>% xml2::write_xml("ImageMagick_logo_notext.svg")
### read edited svg and proceed with logo
img <- image_read_svg("ImageMagick_logo_notext.svg", width=1160) # scaling up the image at import
rlogo_path <- "https://upload.wikimedia.org/wikipedia/commons/1/1b/R_logo.svg"
rlogo <- image_read_svg(rlogo_path, width=80) # scaling down the image at import
rlogo
msk <- image_blank(1000, 400, "transparent") %>%
image_annotate("magick", gravity = "center", size = 250, font = "Aller", weight = 400) %>%
image_channel("Opacity")
txt <- image_blank(1000, 400, pseudo_image = "radial-gradient:red-darkred") %>%
image_composite(msk, operator = "CopyOpacity", gravity = "center")
aura <- msk %>%
image_morphology("Dilate", "Disk:5",5)
bkg <- msk %>%
image_morphology("Dilate", "Disk:2",2) %>%
image_threshold("black", "99%") %>%
image_transparent("white") %>%
image_background("darkred") %>%
image_transparent("black") %>%
image_background("ivory") %>%
image_composite(aura, operator = "CopyOpacity")
magick_logo <- image_canvas_hex(border_color = "midnightblue", fill_color = "ivory") %>%
image_composite(img, gravity = "center", offset = "-50+50") %>%
image_composite(bkg, gravity = "center",offset = "+0-480") %>%
image_composite(txt, gravity = "center",offset = "+0-480") %>%
image_composite(image_canvas_hexborder(border_color = "midnightblue", border_size = 7),
gravity = "center", operator = "Atop")
magick_logo %>% image_scale("30%")
magick_logo %>%
image_scale("1200x1200") %>%
image_write("magick_logo480.png", density = 600)
magick_logo %>%
image_scale("200x200") %>%
image_write("magick_logo200.png", density = 600)
###### Making github card
magick_logo_gh <- magick_logo %>%
image_scale("480x480")
magick_ghcard <-
image_canvas_ghcard(fill_color = "ivory2") %>%
image_composite(magick_logo_gh, gravity = "East", offset = "+30+0") %>%
image_annotate("Advanced image", gravity = "West", location = "+30-80",
color="midnightblue", size=68, font="Aller", weight = 400) %>%
image_annotate("processing in", gravity = "West", location = "+30+0",
color="midnightblue", size=68, font="Aller", weight = 400) %>%
image_composite(rlogo, gravity = "West", offset = "+450-5") %>%
image_annotate("install.packages('magick')", gravity="West", location="+30+90",
color="grey20", size=40, font="Ubuntu Mono") %>%
image_border_ghcard("ivory2")
magick_ghcard %>% image_scale("50%")
magick_ghcard %>%
image_write("magick_ghcard.png", density = 600)
@dmi3kno
Copy link
Author

dmi3kno commented Feb 4, 2020

magick_ghcard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment