forked from jennybc/happy-git-with-r
-
Notifications
You must be signed in to change notification settings - Fork 5
/
process-github-config-diagrams-for-happy-git.R
66 lines (53 loc) · 1.47 KB
/
process-github-config-diagrams-for-happy-git.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
library(tidyverse)
library(magick)
library(fs)
library(here)
# TODO: soon, I should move the source Keynote document (or part of it)
# into this project
exported_paths <- dir_ls("~/rrr/happy-git-with-r-slides/github-configs/2020-06_usethis-motivated-git-diagrams/")
path_file(exported_paths)
# practicing
y <- image_read(exported_paths[[2]])
y
# wow much fiddling here to get the crop geometry right
# the border is just an visual aid
z <- image_crop(y, geometry = "660x640+450+10")
z %>%
image_border(color = "blue")
# doing it to all figs
dir <- here("img", "github-configs")
dir_create(dir)
# clean out previous attempts
dir_ls(dir) %>%
file_delete()
f <- function(file) {
file %>%
image_read() %>%
image_crop(geometry = "660x640+450+10") %>%
image_write(here("img", "github-configs", path_file(file)))
}
walk(exported_paths, f)
cropped_paths <- dir_ls(dir)
path_file(cropped_paths)
name_dat <- tibble(filename = path_file(cropped_paths)) %>%
mutate(number = str_extract(filename, "\\d+(?=[.]jpeg$)"))
usethis_labels <- tribble(
~ number, ~ label,
"001", "no_github",
"002", "ours-you",
"003", "ours-them",
"004", "theirs",
"005", "fork-them",
"006", "fork-them-pull-request",
"007", "fork-ours",
"008", "fork_upstream_is_not_origin_parent",
"009", "maybe_ours_or_theirs",
"010", "maybe_fork"
)
name_dat <- name_dat %>%
left_join(usethis_labels)
file_copy(
cropped_paths,
here("img", path_ext_set(name_dat$label, "png")),
overwrite = TRUE
)