Diagnostic messages are logged in a text file. It resides in folder /test/, but if no such folder exists then the log function is simply redefined to do nothing so that scripts don't have to test if it is enabled for each message.

Here is a form that allows an existing test directory to be renamed (thus freezing any log that might be there. It allows the creation of a test directory (to enable diagnostics) and it allows the log file to be deleted, (thus clearing the log). Regardless what options were chosen it then lists the logfile. Clicking the submit button brings it up in an aside frame.


Reduced image generation

To minimize overhead in regular use, reduced size image files are only created when a 404 file not found error occurs for the desired reduced image. This feature is simple enough to add to existing web pages you might have: Just change the image path to look in the /images/ folder. Assuming there isn't one there yet then the 404 occurs. The 404 script doesn't know where the original is, so that assumes it's in the same folder as the web page that you were viewing, failing that it will look in a folder called /public/.

To reduce the danger of overwriting the original and also to allow conversion of jpg to more efficient WebP format I decided to add the desired file type extension after the current file type extension in the file name. To keep transparnency, png image format need to be maintained by specifying the png result format here for instance is thumb.png.png which is an automatically generated reduced version of thumb.png.

test test

To test it's working first enable and clear the log file with the form above. Then click the gear icon here. That opens a simple html file that has a background and a forground image. It should pop up in the details aside frame and the reduced images will be generated if they aren't there yet. There will be some log messages confirming what happened when you click the submit button above, but you will have to first delete the reduced images fromthe /images/ folder to force it to generate them again if you had done so previously. Be careful to not delete the .access file there, as without it the 404 script will not be called. I'll leave you to check file sizes and have a go at adapting other web pages you might have.

By right clicking in the example frame, some browsers will let you see the source code in that frame. It's just a few simple lines of HTML and the change that had to be made was to specify /images/ as the folder and .WebP as aditional file type extension on the image src attribute.

extra path info

gallery gallery

Php scripts can process different file sets. For instance my ap_gallery.php generates a photo gallery from all the jpg images in a folder. This too can be made more efficient by using the same image reduction technique. My 404 script simply assumes that rather than the source files residing in the same folder as the script, their folder will be determined by extra path info appended to the script name as were the script itself a folder.

folder folder

You can also open the gallery folder without the ap_gallery.php script in the path and you will see it just produces a directory listing of the original images. These are are rather large and would take a long time to render even though visitors probably don't want to see them all in high resolution. When a large number of large image files may need to be processed in a single hit, the server, and the browser too, are liable to time out. You may find you have to try opening it again to have another go and so process some more, but once they are generated the reduced images won't need to be created again. It may be wise to increase the server timeout and I have set mine to 5 minutes because the usual 30 seconds wasn't enough.