In the ‘prev’ and ‘next’ divs I would like to get the ‘title’ and ‘colour’ values stored with the previous and next images in the loop. I tried many combinations of ‘next->’ but couldn’t get it to work.
You have a typo here, is that correct in your code next() not next, i.e. with the parenthesis.
And additionally, you should always check if the image actually exists, like in the examples I linked to. For example, your first image in the loop will never have a previous image and the last one never a next.
Just to clear this up: The error message “Call to a member function title on boolean” or similar messages never appears because of a missing title or meta data but because of a missing object, that means when $image->next() returns false instead of a file object. That is because you can only ever call a class method on an instance of that class.
Well, as I explained above, the first image doesn’t have a previous file and the last one doesn’t have a next file; since you are doing this within a loop, the first file will definitely throw an error when calling prev() and the last one when calling next().
If you want to have an infinite loop, you have to use a custom function.