If you are thinking "that isn't simple at all!" just hold on - when you break it down it really is nothing special. Firstly, a function is defined to handle thumbnail resizing - this uses almost exactly the same code as our previous thumbnail generation script, with the difference being that a variable filename is read in, and also the second parameter to imagejpeg() is used so that the result is saved to a file as opposed to being output to the screen.
Next up is a custom function called scandir_strip(), which is a small extension to the standard function scandir() with the difference that it strips off the first two values in the array - usually the "." and ".." directories, both of which we're not interested in. This is really just there to make the code shorter for printing - it will actually slow your script down to use it as a function.
From there on the code pretty much matches what you saw in the pseudocode. Note that the use of a function for making our thumbnails means we can use array_filter() to do the hard work for us.
Save that script as thumbgen.php, create a directory "fullsize", a directory "thumbnails", and an empty text file "thumbcount.txt". Now, fill the fullsize directory with some JPEG pictures, and try running the script - it should work as expected.
Now, what happens if you change the thumbnails regularly - perhaps you have a webcam, and you add a new picture to the archive every five minutes or so. In the current solution the whole thumbnail archive is deleted each time a file is added or deleted, which is inherently bad. A better solution is to compare the list of files in fullsize against the files in thumbnails, and generate any thumbnails that are missing/delete any thumbnails that no longer exist as full size pictures. An even better solution is to also check the last modified time of each full size picture and thumbnail, regenerating thumbnails if the original has been modified - see what you can come up with!