# How do I save an image that has been shrunk using the image function?

**URL:** https://discourse.processing.org/t/how-do-i-save-an-image-that-has-been-shrunk-using-the-image-function/19651
**Category:** Coding Questions
**Created:** [April 11, 2020, 3:33am UTC](https://discourse.processing.org/t/how-do-i-save-an-image-that-has-been-shrunk-using-the-image-function/19651 "2020-04-11T03:33:39Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Bassam](https://avatars.discourse-cdn.com/v4/letter/b/b38774/32.png) [@Bassam](https://discourse.processing.org/u/Bassam)
#### Post date: [April 11, 2020, 3:33am UTC](https://discourse.processing.org/t/how-do-i-save-an-image-that-has-been-shrunk-using-the-image-function/19651/1 "2020-04-11T03:33:39Z")

</div>

I’m using image(photo1, xpos, ypos, newWidth, newHeight) to shrink a large image.

My question is, how do I save that new shrunken image into a variable so that I can manipulate it further? I want to be able to modify the pixels of the _new_ shrunken image that is created. I don’t want to save a jpg or anything.

`let newImage=image(photo1, xpos, ypos, newWidth, newHeight)` did not work.

Thanks.

[My sketch](https://editor.p5js.org/Bassam/sketches/d6ZEPrmp5)

Here’s my whole sketch:

```auto
let photo1;
let photo2;

function setup() {
  createCanvas(1024, 768);
  background(178, 190, 181);
  

  image(photo1, 50, 175, 300, 150);
  image(photo2, 450, 175, 300, 150);
}

function preload() {
  photo1 = loadImage('sunset.jpg');
  photo2 = loadImage('sunset2.jpg');
}

```

---

<div class="post-metadata">

### Author: ![slow\_izzm](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/slow_izzm/32/5637_2.png) [@slow\_izzm](https://discourse.processing.org/u/slow_izzm)
#### Post date: [April 11, 2020, 4:49am UTC](https://discourse.processing.org/t/how-do-i-save-an-image-that-has-been-shrunk-using-the-image-function/19651/2 "2020-04-11T04:49:50Z")

</div>

Sounds like you want to resize the image. I would do this in preload after you load it.

[https://p5js.org/reference/#/p5.Image/resize](https://p5js.org/reference/#/p5.Image/resize)
