How Can I crop an image in processing js with javascript?

How Can I crop an image in processing js with javascript ?

I would start by googling something like “javascript crop image” for a ton of results. Then I’d put together a MCVE that tries it out in a simple example program.

Got this image round crop sketch in Java Mode. Should be easy to convert it to p5js or pjs: :wink:

Take a look at a sample program on github:

PImage originalImage;
PImage croppedImage = createImage(200, 200, RGB);

void setup() {

size(800, 533);
originalImage = loadImage(“church.jpg”);
}

void draw() {
image(originalImage, 0, 0); // display the church on the screen
croppedImage = originalImage.get(mouseX, mouseY, 100, 100);
image(croppedImage, width/2, height/2);

}

void mouseClicked(){
croppedImage.save(“croppedImage.png”);
}