HOME  → POSTS  → 2004

Simple PHP Gallery 1.1

Projects and Code695 words4 minutes to read

Paul Griffin has just released SPG 1.1! For those who aren’t familiar with this project, Simple PHP Gallery is exactly that—an easy-to-use image gallery system, written in PHP.

There are several new features listed on Paul’s SPG Mini-Site, but there are a few that are my favorites (as I was a beta tester for this and the last versions):

Image Precaching

This was one of the two features that I actually coded the original code for *grin*. In v1.0 and the early v1.1 betas, I got tired of clicking the Next and Previous buttons and having to wait for the new image to load, after I’d just spent several seconds looking at a single picture. It didn’t seem very efficient to me, so I figured why not allow the image loading to happen in the background while I’m spending time looking at this picture anyways.

So, what I did was I figured out what images the Next and Previous buttons were pointing to (which is all dynamic, BTW), and added the Next and Previous to the page at a size of 1x1. I then added inline styles to the image that absolutely positioned them to the top-left corner of the page, and set the visibility to hidden. Doing so allowed the images to load into the cache, while remaining invisible to CSS-enabled browsers (and as two 1 pixel dots on CSS-disabled browsers).

Voila! Image precaching for the previous and next images in sequence.

Image Resizing

Do you have a digital camera that takes pictures at a ridiculously gargantuan size? I used to have one that saved images at 1600x1200. With this feature, you can upload these images, and they will automatically be resized and cached according to the settings in your sp_config.php file. Very useful.

Accesskey Navigation

This was my first suggestion for features in SPG 1.1 after 1.0 launched. I took a 3ds Max class in college, and we had to build something cool from the things we’d learned in the class, and make both a still frame as well as a short rendered video. Mine was about 3 Macs.

Anyways, I went online to grab various images about the computers that I was going to be building. At first, I’d have to open one, then another, then another. Tiring of this quickly, I wrote up a quick HTML page with a JavaScript that would allow me to simply hit Previous or Next to move from one image to the next. The it dawned on me to use accesskeys, since I knew they at least worked in IE and Mozilla (this was during the pre-Firefox “Phoenix” days).

Instantly, I was able to hit Alt+Plus and Alt+Minus to move back and forth through the images. When I recommended this to Paul, we had some discussion, and this is what ended up getting implemented:

The Previous button is Alt+Minus[-]. The Next button is both Alt+Plus[+] as well as Alt+Equals[=]. This is because most QWERTY-language desktop keyboards have a 10-key number pad on the right where [+] and [-] are right next to each other. Most laptops, however, don’t have that, but rather a [-/_] key right next to a [=/+] key (where you have to press shift for the latter). This means that you’d have to press Alt+Minus to move back, and Alt+Shift+Plus to move forward, and that sucks. Allowing Alt+Equals to move forward makes it easy for both Laptop and Desktop QWERTY-keyboards.

Automatically Generated Sub-Folder Details

This was yet another idea that I had for the 1.1 release, and that was to add the number of images in a folder, much like how many people will display the number of comments a blog post has. It just seemed to make sense.

Conclusion

Paul has done a terrific job with writing this software, and I have really enjoyed the opportunity to be a part of it. Heck, I’m probably just as proud of this release as he is, and I’m excited that so many of my suggestions made it into the final release. If you’ve got an image gallery, or you’ve been thinking of setting one up, I would highly recommend Paul Griffin’s Simple PHP Gallery.

Ryan Parman

is an engineering manager with over 20 years of experience across software development, site reliability engineering, and security. He is the creator of SimplePie and AWS SDK for PHP, patented multifactor-authentication-as-a-service at WePay, defined much of the CI/CD and SRE disciplines at McGraw-Hill Education, and came up with the idea of “serverless, event-driven, responsive functions in the cloud” while at Amazon Web Services in 2010. Ryan's aptly-named blog, , is where he writes about ideas longer than . Ambivert. Curious. Not a coffee drinker.