CMS dynamic project page custom code gallery

Wix Studio. For CMS dynamic project pages I need a custom image gallery. The client uses vertical and horizontal images. The gallery must be responsive/stretched.

All gallery images have to be the same height. Horizontal images fill the entire width. Vertical images same height as horizontal and proportionally the same height. The gap between photos - 20px. To keep the same size - images can be cropped.

Similar to Wix Studio Gallery → Grid layout → Fit → 1 image per row. Only gaps must be equal spacing, 20 px.

Can this be achieved using custom (Velo) code?
Any solutions are welcome.

Gallery sample below.

Gallery