-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
59 lines (48 loc) · 1.72 KB
/
README.Rmd
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
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
# hex-stickers <img src="hex-stickers.gif" align="right" width="120" height="138.84" />
<!-- badges: start -->
[![License](https://img.shields.io/github/license/mcanouil/hex-stickers)](LICENSE)
<!-- badges: end -->
```{r, echo = FALSE, message = FALSE}
library(magick)
logos <- sub("\\.png$", "", dir("PNG", pattern = "\\.png$"))
png <- paste0("PNG/", logos, ".png")
svg <- paste0("SVG/", logos, ".svg")
thumb <- paste0("thumbs/", logos, ".png")
resize <- function(path_in, path_out) {
image <- image_read(path_in)
image <- image_resize(image, "278x")
image_write(image, path_out)
}
outdated <- !file.exists(thumb) | file.mtime(thumb) < file.mtime(png)
invisible(Map(resize, png[outdated], thumb[outdated]))
```
```{r, results = "asis", echo = FALSE}
img <- glue::glue('<a href="{png}"><img alt="Logo for {logos}" src="{thumb}" width="120" height="139"></a>')
png_link <- glue::glue('<a href="{png}">{logos}.png</a>')
svg_link <- glue::glue('<a href="{svg}">{logos}.svg</a>')
cell <- paste0('<td align = "center">', img, "<br />", png_link, "<br />", svg_link, "</td>")
cols <- 5
rows <- ceiling(length(cell) / cols)
row_id <- rep(seq_len(rows), each = cols, length.out = length(cell))
row_cells <- split(cell, row_id)
cat("<table>\n")
cat(paste0("<tr>", sapply(row_cells, paste, collapse = ""), "</tr>"), sep = "")
cat("</table>\n")
```
```{r, results = "asis", echo = FALSE}
library(gifski)
ratio <- 3 # 2210/120
gif_hex <- gifski(
png_files = list.files("PNG", pattern = "png$", full.names = TRUE),
gif_file = "hex-stickers.gif",
delay = 1,
width = 2210 / ratio,
height = 2557 / ratio,
loop = TRUE,
progress = FALSE
)
```