You can achieve this using CSS. While it might not be the most SEO-friendly solution, it is, in my opinion, the simplest and quickest one. If you want to display 4 or 5 items, simply adjust the number in the brackets to (-n+4) or (-n+5) accordingly.
/* Initially hide all gallery items */
.gallery__item {
display: none;
}
/* Display only the first three gallery items */
.gallery__item:nth-of-type(-n+3) {
display: block;
}