Skip to content

Instantly share code, notes, and snippets.

@jdbcode
Last active October 9, 2020 17:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdbcode/3302ef12d22889227355813b4d665cf2 to your computer and use it in GitHub Desktop.
Save jdbcode/3302ef12d22889227355813b4d665cf2 to your computer and use it in GitHub Desktop.
R script to add date annotations to a time series GIF created in Earth Engine.
# R script to add date annotations to a time series GIF created in Earth Engine.
library(magick)
gif = "C:/Users/braatenj/Downloads/africa.gif"
dates = c(
'Jan-08',
'Jan-24',
'Feb-09',
'Feb-25',
'Mar-13',
'Mar-29',
'Apr-14',
'Apr-30',
'May-16',
'Jun-01',
'Jun-17',
'Jul-03',
'Jul-19',
'Aug-04',
'Aug-20',
'Sep-05',
'Sep-21',
'Oct-07',
'Oct-23',
'Nov-08',
'Nov-24',
'Dec-10',
'Dec-26')
forward <- image_read(gif)
nframes <- length(forward)
animation <- image_animate(forward, fps = 2)
image_write(animation, path = sub('.gif', '_sized.gif', gif))
forward <- image_read("C:/Users/braatenj/Downloads/africa_sized.gif")
filled = c(forward[1])
comp = forward[1]
for(i in 2:nframes){
comp = image_composite(comp, forward[i])
filled = c(filled, comp)
}
for(i in 1:nframes){
filled[i] = filled[i] %>%
image_annotate(dates[i], size = 40, color = "#E5E4E5", location = "+70+300", font="consolas", boxcolor = rgb(0,0,0)) #, boxcolor = rgb(0,0,0,0.4
}
image_write_gif(filled, path = sub('.gif', '_dates.gif', gif), delay=0.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment