Incremental name for image save

Hello,

I would like to know how to name images so that each image is numbered in the order of recording. Names numbered incrementally.

I use this code:

save("image01.png");

And i want names like: image01, image02, image03… each time i save an image.

Thank you for your help!

1 Like

you can create names as strings anyway you like

function setup() {
  createCanvas(400, 400);
}

function draw() {
  background(220);
}

let count=0;

function fileString() {
  count++;
  return "image_"+year() + "-" + nf(month(), 2) + "-" + nf(day(), 2) + "_" +
    nf(hour(), 2) + "_" + nf(minute(), 2) + "_" + nf(second(), 2)+"_"+count+".png";
}

function keyPressed() {
  if ( key == 's' ) print(fileString());  
}

on key [s] prints to console:

image_2019-11-18_05_23_15_1.png 
image_2019-11-18_05_23_18_2.png 
image_2019-11-18_05_23_19_3.png 
image_2019-11-18_05_23_20_4.png 

try https://editor.p5js.org/kll/sketches/AEQLh_n7y

1 Like

In java processing

https://processing.org/reference/saveFrame_.html

1 Like

you tested that from https://editor.p5js.org ?

Hi, thank you for your reply!

I use your code, and i do this : https://editor.p5js.org/NicolasTilly/sketches/2dD-nn4Pa
and it works!

function setup() {

  createCanvas(400, 400);

  background(220);
  rectMode(CENTER);
  rect(width / 2, height / 2, 100, 100);

}

function draw() {

}


let count = 0;

function fileString() {
  count++;
  return "" + count + ".png";
}


function keyPressed() {
  if (key == 's') save(fileString());
}
2 Likes

good, when it is that simple can also use


let count = 1;

function keyPressed() {
  if ( key == 's' )  save( count++ + ".png");
}

3 Likes

Perfect, even simpler! Thank you!

1 Like