Yeah, I impressed myself on that one

Of course, it does depend on the naming convention of the images.
There probably should be checks to deal with no or one value (no commas), so no need to explode() or loop. It just seemed like a very small improvement in efficiency in exchange for a bigger, uglier snippet.
And of course if it's going to start expanding, with three different possible processing paths, it might as well use a tpl, which would mean enabling properties... like using a shotgun to go after a mosquito.