Okay. Interesting one
Whether that approach would work will depend on the rest of the code, of course, but I don't see why it shouldn't work in principle.
Alternatively, I presume the number 15 is coded somewhere into the program; you could override that when the page loads if there aren't enough images
eg, something approximating this:
var min_images=15; //default number of images.
print "<img src='picture.php?ItemId=$imgnum' />\n";
print "min_images=$rowcount; //not enough pictures, so override min_images.\n";
That's not to say it can't be done in SQL, but I would tend to say that SQL isn't really the best way to do it.
By the way -- one other question to think about... what happens when you've got no image records at all? None of the options discussed so far really deal very well with that (showing blanks would probably work, but would look a bit odd). The trick is to have your program try to cope with whatever SQL gives it, rather than trying to force SQL to conform. It's usually a lot easier that way
All the best with the project.