The best way to achieve it is to have all images in uniformed dimensions. This takes A LOT of time for preparing the images, but is generally worth it. So, let's say you opt for 600x600 px - make sure ALL images use those dimensions. Same goes for attribute images.
If all of your original images are the same dimensions, you should be fine, but as always, there's a but... If your titles that show with the images are different lengths, or maybe multiple words so the title ends up split into two rows, you're back to square one and the layout will be messy. You could mess around with the template and make the container a
flexbox and apply various flex styling, which will then automatically align everything, but it might be a bit overwhelming.
You could also try a jQuery plugin, such as
this. It's quite old, but still works like a charm and, depending on your coding skills, might be easier to implement than flexbox.
Bookmarks