IZSImage Gallery

This script was really fun to make, and has already made my life a bunch easier. It’s not as sophisticated as some other image gallery scripts out there, but if your needs are simple, then it gets the job done. At the very least, it’s a lot prettier than what mod_autoindex will do on its own. I got the idea from the “Thumbnails” view in Windows Explorer If you have a folder on a windows machine that contains pictures, you can set the view to “Thumbnails”, and see a little thumbnail for each image file. If you add a new image, it automagically adds a new thumbnail. In the past, I had to generate thumbnails in the “thumbnails” directory (which I did using CPanel’s Image Manager tool.) Then, I had a script that got a list of all the images in its own directory using `ls`, and then looked for a thumbnail. I had to have a copy of it in each image folder, and also had to manually create the thumbnails, and if a thumbnail was missing, then I got ugly broken images all over the place.

The IZSImage Gallery aims to solve all those problems. See it in action!

Features

  • Just put the gallery.php in your image folder, chmod the folder 667 or 777, and add the mod_rewrite rules to your .htaccess file, and the image folder and all subdirectories are automatically managed.
  • New images that you drop in a folder are automagically included and thumbnail-ized.
  • Supports: .cur, .bmp, .ico, .jpg (or .jpeg), .gif, and .png files.
  • Other filetypes that you drop in a folder are shown as simple links to the file. (For example, if you put a .zip file in there, it’ll just link to it as normal.)
  • Password-protect a subdirectory by placing a .imgpasswd file in the folder.

Requirements

  1. Apache with mod_rewrite.
  2. PHP compiled with GD Image support. (It may work with ImageMagick, but I haven’t tested it with that setup.)
  3. A folder on your webserver that you can devote to images and let the script manage.

Installation

  1. Figure out where you’re going to be storing images on your server. For the sake of argument, let’s say it’s at http://your.site.com/images/. If it’s a different folder, then make the necessary changes.

  2. Create the folder if it doesn’t already exist, and set the permissions (chmod) to 777.

  3. Create a .htaccess file, and put this in it:

    RewriteEngine On
    # replace this with your actual “images” folder, relative to the website.
    # i.e., if your images folder in http://your.site.com/images/gallery/ then set this to /images/gallery/
    RewriteBase /images/
    RewriteRule \.imgpasswd - [F]
    RewriteCond %{REQUEST_FILENAME} -d [NC]
    # change this to the actual (public) path to gallery.php.
    RewriteRule ^(.*)$ /images/gallery.php?dir=$1 [QSA,L]

    Upload this .htaccess file to your images folder.

  4. Get gallery.php.

  5. Open it up in your favorite text editor, and modify the things that it says to modify. (There’s a big section labelled “START EDITING HERE”. You must change the thumbnail reset password before it’ll work. This is an important security feature.)

  6. Upload gallery.php to your images folder.

  7. Put images in the folder. You can also create sub-folders and put images in them. You can also put non-image files in there, but they won’t get thumbnails of course.

Usage

Put images in your “images” folder, and they’ll be thumbnail-ized and linked automagically.

Create sub-folders for other bunches of images, and upload images into there. The sub-folders will be indexed as well. However, DON’T create a subfolder with the name of “thumbnails” and expect to use it. (This is a reserved folder name that the script uses to keep its thumbs.)

Clearing out the Thumbnails

If you somehow end up with a bad thumbnail or two, or have any problems with the thumbnail files getting locked so that you can’t delete them, or if you change the thumbnail file prefix and want to erase the old ones, the script can automatically delete all the existing thumbs and create new ones. Just go to any folder that the script manages, and add ?clearthumbs=YOUR_CLEARTHUMBS_PASSWORD in the URL, but replace YOUR_CLEARTHUMBS_PASSWORD with the password that you set when you edited the script file.

If you want to delete the thumbnail directory entirely, and not re-create it, you’ll have to first delete the images out of that folder, and then clear the thumbs. (Sometimes I’ve found that images created by PHP can become locked so that only the PHP user can modify or delete them. That’s why I added this feature, otherwise I’d still have an image gallery kicking around in my test folder.)

Password-Protecting a Folder

Create a file called .imgpasswd. (Just .imgpasswd with no extension or prefix.) Put this in it:

username:password

Upload it to the directory that you want to protect. If, for some reason, you want to protect /images/subdir/, but you DON’T want to protect /images/subdir/subsubdir/ then you’d put a .imgpasswd file in /images/subdir/ with the username and password, and an empty .imgpasswd file in /images/subdir/subsubdir/.

Licensing

This script is published under a Creative Commons Share-Alike/Attribution license. In short, that means:

  1. You can use the script, but you MUST leave the link to my site intact, and MAY NOT remove any signatures from the code or output.
  2. You can make derivative works based on this script, but all derivative works MUST clearly state that they are based on IZSImage Gallery.
  3. Derivative works MUST be significantly different from the original. You MAY NOT, for example, simply change the title of the script and call it a new work.
  4. Any derivative works, if distributed, must be distributed under the same Creative Commons Share-Alike/Attribution license.
  5. Anything changed in a derivative work must be clearly stated so that your bugs don’t sully my good name.
  6. All rights not specifically granted in the license are reserved.

Have fun!

2 Responses to “IZSImage Gallery”

  1. On May 31st, 2006 at 22:14:20, ss2shin Said:

    Isaac,

    First of all, thank you for this wonderful script. It’s simple yet very convinient, something I was looking for a long time.

    I was able to install it successfully but not able to see the content of directories (No directories or files)

    I’m running Windows 2003 server, and the first page shows “Index of /G:\Comics/” which makes me think this is probably a path issue.

    I also tried to access sub-directories but had the same issue.

    Even a little help would be grealy appreciated.

    A PHP noob.

  2. On July 26th, 2007 at 08:13:17, jrdeahl Said:

    Running W2k sp4,apache 2, php 5. I have got the screen up with “to view” etyc. Didn’t need htaccess but have rewrite turn on. Not using password.

    No images in that dir.

    Thanks,
    John

Leave a Reply

Comments are moderated like crazy using a variety of plugins. There is a very high likelihood that your comment won't show up right away, especially if you have never commented here before, but it was not deleted.

Please be patient, and do not post your comment more than once. It will show up once it is approved.

You must be logged in to post a comment.