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

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.


My sketch

Here’s my whole sketch:

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');
1 Like

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