# How do i make a new image file

**URL:** https://discourse.processing.org/t/how-do-i-make-a-new-image-file/29235
**Category:** Beginners
**Created:** [April 9, 2021, 2:37am UTC](https://discourse.processing.org/t/how-do-i-make-a-new-image-file/29235 "2021-04-09T02:37:23Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![canslp](https://avatars.discourse-cdn.com/v4/letter/c/cc9497/32.png) [@canslp](https://discourse.processing.org/u/canslp)
#### Post date: [April 9, 2021, 2:37am UTC](https://discourse.processing.org/t/how-do-i-make-a-new-image-file/29235/1 "2021-04-09T02:37:23Z")

</div>

i know how to save a PImage as a png but i have to overwrite an existing file. can i manually create a new png file in my data folder and then write a PImage to it?

if i just try to do PImage.save(filename) it tells me i need an “absolute path” which i’m interpreting as a pre-existing file to write over. i know there’s a way to save a screenshot of the entire canvas, how can i do this with just a PImage file?

---

<div class="post-metadata">

### Author: ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)
#### Post date: [April 9, 2021, 6:08am UTC](https://discourse.processing.org/t/how-do-i-make-a-new-image-file/29235/2 "2021-04-09T06:08:54Z")

</div>

You can save the screen with saveFrame(String+".dataType");

```auto
//Examples
saveFrame("image.png"); //saves the screen as image.png
saveFrame("imageNumber"+counter+".jpg"); //saves the screen as a imageNumber<int value>.jpg
saveFrame("frames/frame#####.jpeg"); 
//saves frame in the newly created frames folder, with the current frameCount
//replacing the ##### ; so frame 123 would look like this: frames folder > frame00123.jpeg

```

This means that you can actually customize the string (or use the default function of processing to replace the ### with frameCount.

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [April 9, 2021, 7:26am UTC](https://discourse.processing.org/t/how-do-i-make-a-new-image-file/29235/3 "2021-04-09T07:26:14Z")

</div>

Hello,

> [@canslp](#):
>
> can i manually create a new png file in my data folder and then write a PImage to it?

My efforts:

```auto
PImage photo1, photo2;

void setup() 
  {
  size(100, 100);
  photo2 = createImage(50, 50, RGB);
  photo2.save("\\data\\PImage2.png");
  
  photo1 = loadImage("PImage1.png");
  photo1.resize(50, 50);
  photo1.save("\\data\\PImage2.png");
  
  photo2 = loadImage("PImage2.png");
  }

void draw() 
  {
  image(photo2, 0, 0);
  }

```

References:

- [PImage / Reference / Processing.org](https://processing.org/reference/PImage.html)
- [createImage() / Reference / Processing.org](https://processing.org/reference/createImage_.html)

PImage.png used was from references:

![PImage](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/f/f577b6289a3e9b0fe644a10c5672932b7faa76d5.png)

`:)`

---

<div class="post-metadata">

### Author: ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)
#### Post date: [April 9, 2021, 8:13am UTC](https://discourse.processing.org/t/how-do-i-make-a-new-image-file/29235/4 "2021-04-09T08:13:15Z")

</div>

> [@glv](#):
>
> `"\\data\\`

what does this do? Is it just the normal “data/…”?

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [April 9, 2021, 9:49am UTC](https://discourse.processing.org/t/how-do-i-make-a-new-image-file/29235/5 "2021-04-09T09:49:39Z")

</div>

> [@glv](#):
>
> `photo2.save("\\data\\PImage2.png");`

There is a comment about _escape sequence_ and the` \\` here:  
_[String / Reference / Processing.org](https://processing.org/reference/String.html)_

This saves it to the _data folder_ otherwise it just saved it to _sketch folder_.

This works also:

```auto
PImage photo1, photo2;

void setup() 
  {
  size(100, 100);
  photo2 = createImage(50, 50, RGB);
  photo2.save("/data/PImage2.png");
  
  photo1 = loadImage("PImage1.png");
  photo1.resize(50, 50);
  photo1.save("/data/PImage2.png");
  
  photo2 = loadImage("PImage2.png");
  }

void draw() 
  {
  image(photo2, 0, 0);
  }

```

`:)`

---

<div class="post-metadata">

### Author: ![canslp](https://avatars.discourse-cdn.com/v4/letter/c/cc9497/32.png) [@canslp](https://discourse.processing.org/u/canslp)
#### Post date: [April 9, 2021, 12:20pm UTC](https://discourse.processing.org/t/how-do-i-make-a-new-image-file/29235/6 "2021-04-09T12:20:23Z")

</div>

i know how to save a screenshot, how do i save a PImage without drawing it onto the screen first

---

<div class="post-metadata">

### Author: ![canslp](https://avatars.discourse-cdn.com/v4/letter/c/cc9497/32.png) [@canslp](https://discourse.processing.org/u/canslp)
#### Post date: [April 9, 2021, 12:21pm UTC](https://discourse.processing.org/t/how-do-i-make-a-new-image-file/29235/7 "2021-04-09T12:21:30Z")

</div>

i’ve been trying to use PImage.save(), don’t you need to already have a file that’s called that? i want to make new image files and i can’t do that with save because it needs an ‘absolute path’

essentially i’m doing image processing to change the colors of images- but i don’t want to have to do that every time because it’s slow so i wan’t to save each new color version of the image file. but i can’t do out.save(“data/”+name); because name isn’t an ‘absolute path’- it’s a variable

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [April 9, 2021, 1:47pm UTC](https://discourse.processing.org/t/how-do-i-make-a-new-image-file/29235/8 "2021-04-09T13:47:59Z")

</div>

> [@canslp](#):
>
> because it needs an ‘absolute path’

Try these added to your PImage file name:

```auto
println (dataPath(""));
println (sketchPath(""));

```

`:)`

---

<div class="post-metadata">

### Author: ![canslp](https://avatars.discourse-cdn.com/v4/letter/c/cc9497/32.png) [@canslp](https://discourse.processing.org/u/canslp)
#### Post date: [April 9, 2021, 4:39pm UTC](https://discourse.processing.org/t/how-do-i-make-a-new-image-file/29235/9 "2021-04-09T16:39:07Z")

</div>

oh wow that totally worked, thanks!
