Does the template use a plug-in for the gallery itself? Because if it’s something like NextGEN Gallery, you can paginate it right from the settings menu. That would be the best way.
For most websites, pagination is as easy as using the template tags;
<?php previous_post(); ?>
<?php next_post(); ?>
Maybe give them a try in your code and see if it works.
That wouldn’t break off your images after twenty, but allow you to paginate between previous and next posts. If you publish twenty images in each post, you could bodge together something like what you have in mind.