Rstats
Animation
Author

George Girton

Published

November 14, 2022

Hummingbirds in flight

Still photo of hummingbird in flight

At the beginning of November, I saw a hummingbird in the garden (not the bird above, which I photographed elsewhere), and started to photograph it. I clicked my phone, took a photo, zoomed in, and started to walk toward the bird. Hovering briefly, it flew up and disappeared into the air.

I have observed, while photographing bees, is that although there may be a single “best frame” of the live photo, examining the motion sequence has its own fascination. A still bee photo is amazing (“be still my bee”), but a bee movie …

The same, I thought, is true of the bird. But how can I share this beauty here?

Click button at right or left to advance by frame:

I ended up using the slickR package, which wraps a javascript carousel library slick (references at end)

Code
library(slickR)

    bird_frame_filenames <- list.files("idata/", pattern=".jpg", full.names = TRUE)

slickR(bird_frame_filenames, height = 250, width='80%') +
  settings(dots = TRUE,
  infinite= TRUE,
  speed = 0,
  fade = TRUE,
  cssEase = 'linear')

What I did

The iPhone “live photo” stores photos in a format called ‘HEIC’. Instead of using that, I created a .GIF image, using an app called “Lively”. I wrote to those app developers asking if there was a way to export the images as individual jpegs.

But then!

Before they had a chance to reply, I remembered image magick. I’ll just make the frames myself. Since you can make a gif directly, I did not need the Lively app at all … but still, I’m leaving the watermark in as free advertising :-)

Here’s the code for exporting the frames. (I ran it in R Studio, it isn’t part of this page)

``` {{r}}
library(magick)

bird1 <- magick::image_read("idata/IMG_8350_Lively.gif")

#https://www.r-bloggers.com/2020/08/basic-manipulation-of-gif-frames-with-magick/

bird1   ## yes, it flies in RStudio!
print(bird1)
length(bird1)


## Here I looked at the frames one at a time
bird1[1]
bird1[16]
bird1[17]
bird1[18]
bird1[19]
bird1[29]
bird1[28]

## oops!
for(i in 1: length(bird1)) {
  eachname = paste0("humm",as.character(i),".jpg")
  magick::image_write(bird1[i],path=eachname)
}

### Then noticed I had out-of-sort order frames in the final product, so I went back and made it right, but FIRST I changed the filenames by hand for the first ten LOL not very pipeline

for(i in 1: length(bird1)) {
  zeropadnum <- sprintf("%03i",i)
  eachname = paste0("humm",zeropadnum,".jpg")
  magick::image_write(bird1[i],path=eachname)
}


```

So, that is how I prepared the images.

Muchas gracias!

I did not crack how to load the list of images until I came across this link:

https://kandi.openweaver.com/javascript/yonicd/slickR#Code-Snippets

and also found the settings I needed in this explanation by the original author, under the “Fade” example:

http://kenwheeler.github.io/slick/

I’m assuming this all will work on the server but if not … maybe I will try to make it work by somehow putting the hummingbird image onto geom_point(), using Allison Horst’s Rosetta Stone:

https://observablehq.com/@observablehq/plot-from-ggplot2

postscript: It seems to work!

— all photos Copyright © 2022-2024 George D Girton all rights reserved