The pixel array can be confusing:
This was a window originally sized at 500×500. The image is 500×333. In draw(), a call is made to size(400,333), and the length of pixels is output immediately after.
First of all, the calls to size() after the initial call do not change the size of the window itself. Instead, they change the area available for output. This means that if you removed the call to size(400,333), the rest of the picture would be shown (it would fill the blue area). That call shrinks the area available for output, and the picture is truncated to the size of the red area.
The pixels array is everything displayed in the window- including grey areas. So, calls to size(), loadImage(), image(), etc. do not change the size of pixels. Throughout the program that created this picture, the length of pixels was 251500 (500×500+ 1500 mystery pixels).
The PImage.pixels array (separate from the other pixels array, which is global) always represents the picture, even when part of it is made non-visible. This is quite useful… I wish I had figured that out earlier.
When using the PImage.pixels array:
When using the global pixels array: