Of course this is possible.
No... I don't have an example, becuase what you want is baaaaaaaaad_practice
Why is it bad?
Assume you grabbed all your images out of the database with the user request.
..ok..
Now imagine having to resize and and create a temp directory on your HTTP_DOC_ROOT
to create all 20 images in...
Now you see that this is going to gobble processes faster than a fatty at a pizza feast.
And really slow down the page request, because your thumb gallery will take awhile to be generated since all those images must be resized and stored BEFORE any HTML is outputted, and if you try outputting your HTML before the images are ready, you'll get a page full of red X.
And that's not very fun now is it.
So, what I recomend is uploading a .zip (or whatever) file as a bundle of images and having the server create a directory full of thumbs then and there and then DB the larger images if so desired.
That way, you can just use the scripts you found and enjoy a low stress page process.