Skip to content

Instantly share code, notes, and snippets.

@pepijn-devries
Last active February 19, 2019 22:11
Show Gist options
  • Save pepijn-devries/2c39fbbdc2bef5b718a33fe07b9da3c6 to your computer and use it in GitHub Desktop.
Save pepijn-devries/2c39fbbdc2bef5b718a33fe07b9da3c6 to your computer and use it in GitHub Desktop.
GIF to Amiga IFF
## use the magick package to read a GIF file:
library(magick)
## use AmigaFFH to convert into Amiga IFF file,
## make sure to use version 0.2.0 or newer:
library(AmigaFFH)
## Read the GIF animation we created in an earlier post:
earth <- image_read("http://3.bp.blogspot.com/-CCurVbm1ChI/VdC2NrqeeaI/AAAAAAAAx_8/lyO9mFyVhU8/s1600/globe.gif")
## convert the magick object into a list of raster objects:
earth.rst <- lapply(earth, function(x) {
as.raster(x)
})
## reduce the number of frames:
earth.rst <- earth.rst[round(head(seq(1, length(earth.rst) + 1, length.out = 11), -1))]
## create an IFF ANIM with a 16 colour palette.
## Note that this may take some time as it is all scipted source:
earth.iff <- rasterToIFF(earth.rst,
depth = 4,
indexing = function(x, length.out)
index.colours(x, length.out, dither = "floyd"))
## save to an IFF file:
write.iff(earth.iff, "earth.iff")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment