Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
customised, automatised wedding vignettes
library(png)
#' Print Table Vignette
#'
#' @param out_dir
#' @param img
#' @param name
#' @param file_name
#' @param two_sided
#'
#' @return
#'
print_table_vignette <- function(out_dir, img, name, file_name, two_sided = TRUE){
h <- dim(img)[1]
w <- dim(img)[2]
out_file_name <- sprintf("%s/%s.png",
out_dir,
file_name)
png(out_file_name, width=w, height=h)
par(mar=c(0,0,0,0), xpd=NA, mgp=c(0,0,0), oma=c(0,0,0,0), ann=F, family = 'snell')
plot.new()
plot.window(0:1, 0:1)
usr <- par("usr")
rasterImage(img, usr[1], usr[3], usr[2], usr[4])
text(.5, y = .25, name, cex=8, col="black")
if (two_sided)
text(.5, y = .75, name, cex=8, col="black", srt = 180)
dev.off()
}
dir_vignettes <- sprintf("%s/vignettes", PATH_TO_OUT_FILES)
if( !dir.exists(dir_vignettes))
dir.create(dir_vignettes)
# loading font according to
# http://rcrastinate.blogspot.com/2015/08/changing-font-of-r-base-graphic-plots.html
quartzFonts(snell = c("Snell Roundhand", "Snell Roundhand Bold", "Snell Roundhand Black",
"Snell Roundhand Bold"))
img <- readPNG(PATH_TO_PNG_FILE)
# dataframe with columne name
guests <- read.csv2(PATH_TO_GUEST_FILE, stringsAsFactors = F)
# we might have duplicates, we need them all :)
guests$file_name <- make.names(gsub(" ", "_", tolower(guests$name)), unique = T)
for (i in 1:nrow(guests)){
x <- guests[i, ]
print_table_vignette(dir_vignettes, img, x$name, x$file_name)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.