Cropping an image buffer on transparency?

I’d like to crop/copy an image buffer in #p5js so that only the non-transparent part is kept/copied … any ideas how to do that (quickly)!? Thanks!

1 Like


You could loop through the pixels of the buffer

do it four times starting at each corner and working along an edge

then work inwards until you get the first pixel with color

this would then give you the places to start and end your crop

Hi, I found a solution using Javascript and I have ported it to p5js: trimCanvas -

1 Like