Use magick package
hadley opened this issue · 8 comments
Because that would be easier for people than requiring they have magick installed.
@jeroen It seems image_animate()
does not support file paths as inputs. That means we will have to generate all images, read them into memory, and call this function. Is there a reason why most image_*
functions only support raw objects?
I don't understand the question. You should read the images with image_read
:
image <- image_read(c("img1.png", "img2.png" "img3.png"))
image_animate(image)
I mean why cannot we use image_animate(c("img1.png", "img2.png" "img3.png"))
and must read the files into memory?
Ah ok. Well under the hood imagemagick always needs to read files into memory before it can do any sort of manipulation or format conversion. So even if we would support that syntax, it would not affect performance.
In the beginning I did indeed overload the image
parameter so that you could give it a path and it would automatically image_read()
the image, but I backed out from that. I don't remember why, I'd have to look back into the commit logs...
I see. I need to check whether it really matters when reading a large amount of images (I was a little concerned about the memory use; ImageMagick probably won't read all images into memory at once. I'm not sure). Thanks!
OK let me know what you find. I would guess that ImageMagick reads all images at once, because some transformations and effects manipulate multiple frames simultaneously.
I have finally gotten around benchmarking this. On my machine the magick
slightly outperforms the command line utility on this simple benchmark. So I don't think this should be a concern.
Unit: seconds
expr min lq mean median uq max neval
magick 8.675735 9.342597 10.15568 10.13141 11.11263 11.51604 5
cmdline 10.776482 10.797034 11.30854 11.01312 11.37173 12.58433 5
I am quite sure that under the hood, the command line utility also read all images before creating the animation, otherwise it would be very difficult to derive the image disposal, etc.
Note that the magick
package works out of the box on all platforms without requiring the user to install any additional software. This is a pretty big benefit for windows / osx users.
In addition, shelling out is never 100% reliable because you might have too many files so that the command becomes too long, or if there are non-ascii characters in filenames, etc, etc.
@jeroen Your code for magick
package helped me in creating gif (12 png files) for my project. Wanted to clarify whether I can output the gifs without the function ?
I did go through image_write()
arguments but output wasn't one of them.