How to define an image style where images are the exact same dimensions (e.g. grid of square images), without cropping or distorting the image? On my site, images of any shape can be uploaded, for example:



I want these to display in a grid where every image is the same size and shape (in my case, square) - due to the nature of the images, I don't want to use cropping and I don't want any distortion of the aspect ratio, but the backgrounds can be extended. This also needs to be applied to the image itself, not a CSS wrapper. 

For example, I'd like the end result to look like this:



Everything I've tried using various combinations of "scale" and "resize" either doesn't give consistent final sizes depending on whether the original was tall or wide, or distort the image. Cropping isn't an option. How can I do this?
If you don't mind applying a block background colour, this seems to be possible with Imagecache Actions module.


Download and enable the Imagecache Actions module and its imagecache_canvasactions submodule.
Add a normal "scale" action to the desired size (300 x 300). This keeps the aspect ratio.
After, add a "Define canvas" action, then set to the same dimensions under "exact size". 
Make sure "Resize canvas under image" is ticked, choose an appropriate background colour, and go. This fills in any gaps to the desired size with whatever colour you choose (or transparency if you choose no colour).