Thank you very much for your reply. In the meantime I tried creating an array of images, crop them into a square and then resize them. I move the function call to the setup and resizing it. But for some reason my images are no longer being cropped only resized. What could the issue be? This happens even if I used resize() after the copy() function. Thanks for your help.
//'+' or '=' and '-' or '_' to go forwars and backwards through the library.
PImage[] img= new PImage[5]; //Create array of images, length of 5
int i = 0; //Used to choose which image is shown. Can use + and - to change to next picture.
void setup() {
size(100, 100); //Size of screen is size of orininal picture
for (int i=0; i<img.length; i++) { //Load the images
img[i] = loadImage( "pic" + i + ".jpg");
squareImg(img); //The function found below
img[i].resize(100, 100);
}
}
void draw() {
background(0);
image(img[i], 0, 0);
}
PImage[] squareImg(PImage img[]) { //Function with the image parameter
if (img[i].width>img[i].height) { //If the image width is larger than height, then crop the side
//src, sourceX, sy, sw, sh, destinationX, dy, dw, dh
copy(img[i], 0, 0, img[i].height, img[i].height, 0, 0, img[i].height, img[i].height);
}
else if (img[i].width<img[i].height) { //If the image height is larger than height, then crop the bottom
//src, sourceX, sy, sw, sh, destinationX, dy, dw, dh
loadPixels();
copy(img[i], 0, 0, img[i].width, img[i].width, 0, 0, img[i].width, img[i].width);
}
else if (img[i].width==img[i].height) { //If it's already a perfect square, then don't crop anything
//src, sourceX, sy, sw, sh, destinationX, dy, dw, dh
copy(img[i], 0, 0, img[i].width, img[i].height, 0, 0, img[i].width, img[i].height);
}
return img; //Returns the img
}
void keyPressed () { //Used to selected next picture.
if (key == '+' || key == '=') {
if (i >= img.length-1) {
i = 0; //Resets the image to img[0] when at last image
}
else {
i++; //Incraments to next image
}
}
else if (key== '-' || key=='_') {
if (i < 1) {
i = img.length-1; //Resets the image to img[5] when at first image
}
else {
i--; //Decraments to next image
}
}
}