# Incremental name for image save

**URL:** https://discourse.processing.org/t/incremental-name-for-image-save/15599
**Category:** Coding Questions
**Created:** [November 17, 2019, 10:16pm UTC](https://discourse.processing.org/t/incremental-name-for-image-save/15599 "2019-11-17T22:16:42Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![nicolas](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/nicolas/32/7166_2.png) [@nicolas](https://discourse.processing.org/u/nicolas)
#### Post date: [November 17, 2019, 10:16pm UTC](https://discourse.processing.org/t/incremental-name-for-image-save/15599/1 "2019-11-17T22:16:42Z")

</div>

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:

```auto
save("image01.png");

```

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

Thank you for your help!

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [November 17, 2019, 10:25pm UTC](https://discourse.processing.org/t/incremental-name-for-image-save/15599/2 "2019-11-17T22:25:12Z")

</div>

you can create names as strings anyway you like

```auto
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:

```auto
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](https://editor.p5js.org/kll/sketches/AEQLh_n7y)

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [November 18, 2019, 6:42am UTC](https://discourse.processing.org/t/incremental-name-for-image-save/15599/3 "2019-11-18T06:42:18Z")

</div>

In java processing

[https://processing.org/reference/saveFrame\_.html](https://processing.org/reference/saveFrame_.html)

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [November 18, 2019, 7:16am UTC](https://discourse.processing.org/t/incremental-name-for-image-save/15599/4 "2019-11-18T07:16:27Z")

</div>

you tested that from [https://editor.p5js.org](https://editor.p5js.org) ?

---

<div class="post-metadata">

### Author: ![nicolas](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/nicolas/32/7166_2.png) [@nicolas](https://discourse.processing.org/u/nicolas)
#### Post date: [November 18, 2019, 10:57am UTC](https://discourse.processing.org/t/incremental-name-for-image-save/15599/5 "2019-11-18T10:57:32Z")

</div>

Hi, thank you for your reply!

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

```auto
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());
}

```

---

<div class="post-metadata">

### Author: ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)
#### Post date: [November 18, 2019, 11:02am UTC](https://discourse.processing.org/t/incremental-name-for-image-save/15599/6 "2019-11-18T11:02:18Z")

</div>

good, when it is that simple can also use

```auto

let count = 1;

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

```

---

<div class="post-metadata">

### Author: ![nicolas](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/nicolas/32/7166_2.png) [@nicolas](https://discourse.processing.org/u/nicolas)
#### Post date: [November 18, 2019, 12:04pm UTC](https://discourse.processing.org/t/incremental-name-for-image-save/15599/7 "2019-11-18T12:04:57Z")

</div>

Perfect, even simpler! Thank you!
