The current implementation of p5js's loadImage() for gifs is quite slow. Using an <img> tag in html with a gif will showup much faster than p5js. This suggests that there is perhaps a faster way of loading gifs.
Take this rick-roll.gif puzzle for instance: https://puzzlefy.netlify.app/?image=https://media0.giphy.com/media/Ju7l5y9osyymQ/200.gif&cols=5&rows=4
Here are the loading steps and their times for this example:
| Step |
Millis |
Seconds |
Description |
| Load |
5102 millis |
5 sec |
Loading the gif |
| Cut |
3232 millis |
3 sec |
Cutting the image with image.get(x, y, w, h) rows * cols * frames times |
| Puzzlefy |
3238 millis |
3 sec |
Creating jigsaw masks and graphics, applying the masks to the tiles |
| Pieces |
9 millis |
0 sec |
Creating all the Piece objects |
total: 11 sec
- Perhaps the cutting/puzzlefying can also be optimized as they do take a solid 6 seconds in this example to execute.
- The implementation of p5js's
loadImage() can be found here
The current implementation of p5js's
loadImage()for gifs is quite slow. Using an<img>tag in html with a gif will showup much faster than p5js. This suggests that there is perhaps a faster way of loading gifs.Take this
rick-roll.gifpuzzle for instance: https://puzzlefy.netlify.app/?image=https://media0.giphy.com/media/Ju7l5y9osyymQ/200.gif&cols=5&rows=4Here are the loading steps and their times for this example:
image.get(x, y, w, h)rows * cols * framestimesPieceobjectstotal: 11 sec
loadImage()can be found here