For some time now I wanted to create a zoom-in/out animation to illustrate better the image mosaic that fascinates me so much. Seeing tiny images that lack resolution can’t convey the absolutely humongous images that the mosaic script creates, some of them can be images that are over 500 Mb or larger.
First I tried FFmpeg and had some success with it but it proved inconsistent and challenging to configure sometimes getting read errors or scripts stopping in the middle of processing.
So I looked at how to use the already available array in memory to try to resize it and get it to create a series of in-memory images with progressive “zoom” and combine them to make a gif or video. I've been trying for some time until I found a snippet that does just that. Since then I’ve lost the source of the snippet, and if anyone knows where it came from I’ll update the post.
But, for now, the result is this:
The default output is gif but we can also save it using the MoviePy library. Note that the resulting images are extremely large and the gif shown above has been compressed to oblivion for it to be accepted at the substack to display. The resulting gifs from this code are very sharp as it zooms into 1:1 of the original. That’s why the input image has to be of a very large resolution. For example, if the original image is 3240 pixels the zoom will be 3x as the set dimension of the video is 1080px. This can be changed in code in the function save_zoom_gif.
Some of the other switches we can play with are:
The code snippets are :
If you change max_res in the following function you can zoom in on smaller or large images and will generate smaller or larger videos depending on what you set the max resolution to.
The full code for this can be found, as always, on GitHub.