Skip to content
Related Articles
Open in App
Not now

Related Articles

p5.js Image numFrames() Method

Improve Article
Save Article
  • Last Updated : 23 Sep, 2020
Improve Article
Save Article

The numFrames() method of p5.Image in p5.js library is used to return the total number of frames of the GIF animation.



Parameters: This function accept does not accept any parameter.

Return Value: This method returns a number that represents the total number of frames of the GIF animation.

The following libraries are included in the “head” section of the HTML page while implementing the following examples.

<script src=”p5.Image.js”></script>
<script src=”p5.min.js”></script>

Example: The example below illustrates the numFrames() method in p5.js


function preload() {
    example_gif =
function setup() {
    createCanvas(500, 300);
    text("Click on the button to get " +
         "the total number of frames",
         20, 20);
    frameBtn =
      createButton("Get number of frames");
    frameBtn.position(30, 40);
function draw() {
  // Draw the GIF on screen
  image(example_gif, 20, 60, 240, 120);
function getTotalFrames()
  // Get the total number of frames
  let numberOfFrames =
  text("Number of frames in the GIF is: "
       + numberOfFrames, 20, 200);


Online editor:
Environment Setup:

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!