Controls number of gif repeats in R markdown.

I have added several gif files to an rmarkdown presentation (ioslides output). I would like to control the number of times it loops - the default behavior is endless repeat. Is this possible? I tried searching the rmarkdown documentation without much success.

knitr::include_graphics("some_meme.gif")

Hi,

I don't know if markdown has this option, but you could consider editing the gif itself and adjusting the loop count. There are tons of online tools that can help you with this:

Hope this helps,
PJ

I think you can use magick package to modify your original gif.
Something like:

library(magick)
gif <- image_read("https://jeroen.github.io/images/banana.gif")
# this is the original gif
gif
gif2 <- image_animate(gif, loop = 3)
# gif that will loop only two times
gif2
image_write(gif2, "new_banana.gif")

See

You have also so specific function gif that uses gifski

Hope it helps

1 Like