Skip to content

Instantly share code, notes, and snippets.

@jimhester
Last active August 26, 2017 08:39
Show Gist options
  • Save jimhester/c4083850f419835f2f0346b9714f1d5e to your computer and use it in GitHub Desktop.
Save jimhester/c4083850f419835f2f0346b9714f1d5e to your computer and use it in GitHub Desktop.
library(gh)
library(tidyverse)
library("magick")
library(glue)
dir.create("data")
repos <- gh::gh("/orgs/:org/repos", org = "tidyverse", .limit = Inf) %>% map_chr("name")
urls <- repos %>%
map(safely(function(x) {
res <- gh::gh("/repos/:owner/:repo/stats/contributors", owner = "tidyverse", repo = x, .limit = Inf)
tibble(
url = map_chr(res, ~ .x$author$avatar_url),
nms = map_chr(res, ~ .x$author$login))}))
urls <- map_df(urls, "result")
saveRDS(file = "urls.RDS", urls)
# adapted from http://livefreeordichotomize.com/2017/07/18/the-making-of-we-r-ladies/
save_image <- function(url, nms){
picture <- file.path("data", glue::glue("{nms}.jpg"))
if (file.exists(picture)) { return() }
image_read(url) %>%
image_scale("100x100!") %>%
image_write(picture, format = "jpeg")
}
pwalk(urls, save_image)
### Remove default avatars
files <- list.files("data", full.names = TRUE)
dir.create("bak")
check_image <- function(pic) {
img <- jpeg::readJPEG(pic)
if (any(dim(img) == 3)) {
if (length(unique(img[,1,1])) == 1) {
file.rename(pic, file.path("bak", basename(pic)))
}
}
}
purrr::walk(files, check_image)
## devtools::install_github("LucyMcGowan/RsimMosaic")
library("RsimMosaicLDM")
set.seed(108)
composeMosaicFromImageRandomOptim(
originalImageFileName = "data/hadley.jpg",
outputImageFileName = "tidyverse.jpg",
inputTileSize = 100,
imagesToUseInMosaic = "data",
removeTiles = FALSE,
fracLibSizeThreshold = 0.01
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment