Is there a way to make resize(300) generate squares in that format by filling the missing pixels white if there is an portrait or landscape image provided?
I dont believe so. The image needs to be atleast as big or greater than the dimensions you give it with crop() and resize(). You could possibly fake the white fill by getting clever with CSS grid or flexbox. Basicly give the parent element the desired crop dimensions and use vertical and horizontal centering so it looks like the image is that size, together with a white background on the element.
If you want it baked into the image, you will need to extend either the GD or Imagemagic drivers, and even then im not 100% sure is possible, but it might from what ive read of the GD documentation.