Kethigallery is a PHP class designed to allow you to quickly and easily turn a directory of images on your website into an attractive looking, highly configurable gallery.
Features
- Three distinct view modes:
- Thumb gallery mode: shows a grid of thumbnails. When you click a thumbnail, you're shown a larger thumbnail of that image in slideshow mode.
- Slideshow mode: shows large-sized thumbnails of your images with previous and next image buttons. Clicking the thumbnail shows the full size image.
- Linker mode: for creating a small preview of your full gallery in another file. Thumbnails in linker mode point to the full version of your gallery.
- Support for recursive folder structures - can show all images in all subfolders.
- Automatic thumbnail creation, thumbnails respect aspect ratio of your images.
- Support for setting a title and description on your images. Metadata can be stored in either MySQL (requires a bit extra configuration) or a flat text file (done automatically if MySQL is not enabled).
- Graphical administrative tools integrated directly into the UI.
- UI drawn with semantic XHTML allowing you to easily style it to perfectly fit the look and feel of your website with CSS.
- High interface configurability. See all options below.
Live demos
- Demo in thumb gallery mode
- Demo in linker mode (linking to the gallery from a preview on another page)
Download
Example code
<?php
require_once('inc/kethigallery.inc.php'); // include kethigallery
$kethigallery = new kethigallery('folder/with/images'); // instantiate kethigallery
$kethigallery->set_admin_url('gallery_admin'); // set admin url
$kethigallery->set_admin_username('username'); // set admin username
$kethigallery->set_admin_password('password'); // set admin password
/* ... */ // set any optional preferences here
$kethigallery->init(); // initialize kethigallery
?>
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.1//EN' 'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'>
<head>
<meta http-equiv='Content-Type' content='application/xhtml+xml; charset=utf-8' />
<title>Kethigallery Demo</title>
<link rel='stylesheet' type='text/css' href='kethigallery_example.css' />
</head>
<body>
<?php $kethigallery->draw_gallery(); /* draw gallery markup */ ?>
</body>
</html>
Example code for linker mode (linking to the gallery from a preview on another page)
<?php
require_once('inc/kethigallery.inc.php'); // include kethigallery
$kethigallery = new kethigallery('folder/with/images'); // instantiate kethigallery
$kethigallery->set_admin_url('gallery_admin'); // set admin url
$kethigallery->set_admin_username('username'); // set admin username
$kethigallery->set_admin_password('password'); // set admin password
$kethigallery->set_thumbs_per_page(3); // an optional preference
$kethigallery->init(); // initialize kethigallery
?>
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.1//EN' 'http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'>
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en'>
<head>
<meta http-equiv='Content-Type' content='application/xhtml+xml; charset=utf-8' />
<title>Kethigallery Demo (linker mode)</title>
<link rel='stylesheet' type='text/css' href='kethigallery_example_linker.css' />
</head>
<body>
<h1>Welcome to the Kethigallery Linker Demo</h1>
<p>This page demonstrates how to integrate a preview of your gallery into your
site's existing content. The thumbnails on this page link to the full gallery
over at (in this case) kethigallery_demo.php.</p>
<p>Click on one of the below thumbnails to enter the gallery slideshow. Or click
<a href='kethigallery_demo.php'>here</a> to see the whole gallery in thumb
gallery mode.</p>
<?php $kethigallery->draw_linker_to('kethigallery_demo.php'); /* draw linker markup and
point it to main gallery */ ?>
</body>
</html>
Class method documentation
- kethigallery(string $img_dir)
Constructor - instantiates the class. Accepts a string argument containing the relative path to the folder with the desired images to display in the gallery. - init()
Initializes Kethigallery and processes your settings. This method must be called prior to any headers or text being sent to the browser.
Settings methods
These methods can be called to configure your instance of Kethigallery. All of these methods must be called prior to init().
- set_admin_url(string $url)
Sets the URL for the admin page. The default value is kethigallery_admin. Example: your_gallery.php?kethigallery_admin. It is strongly recommended that you change this default. - set_admin_username(string $username)
Sets the username for the admin page. The default value is username. It is strongly recommended that you change this default. - set_admin_password(string $password)
Sets the password for the admin page. The default value is password. It is strongly recommended that you change this default. - use_mysql(string $server, string $dbname, string $username, optional string $password, optional string $dbprefix)
Establishes a new MySQL connection to a specified server and database using specified username and (optional, but recommended) password. Optional argument $dbprefix specifies what (if any) string prefix to give the table name kethigallery_metadata that must be created to store metadata. - use_existing_mysql(optional string $dbprefix)
Enables MySQL support using an already established database connection elsewhere in your script. Optional argument $dbprefix specifies what (if any) string prefix to give the table name kethigallery_metadata that must be created to store metadata. - set_sort_asc()
Sorts images by file name in ascending order rather than the default descending order. - disable_recursion()
Ignores subfolders of $img_dir rather than the default recursive behavior. - disable_thumb_maker()
Turns off the automatic thumbnail creation. - set_thumb_gallery_mode_thumb_width(int $n)
Sets the width of the thumbnails in thumb gallery mode. Height is determined by aspect ratio. (Default value is 210.) - set_slideshow_mode_thumb_width(int $n)
Sets the width of the thumbnails in slideshow mode. Height is determined by aspect ratio. (Default value is 950.) - set_linker_mode_thumb_width(int $n)
Sets the width of the thumbnails in linker mode. Height is determined by aspect ratio. (Default value is 150.) - set_thumbs_per_row(int $n)
Sets the number of thumbnails per row in thumb gallery or linker modes. (Default value is 4.) - set_thumbs_per_page(int $n)
Sets the number of thumbnails per page in thumb gallery mode or the number of thumbnails total in linker mode. (Default value is 16.) - truncate_titles_at(int $n)
Sets the number of characters of the image title to display in thumb gallery or linker modes. Truncation will not cut off the middle of a word. (Default value is 25.) - truncate_descriptions_at(int $n)
Sets the number of characters of the image description to display in thumb gallery or linker modes. Truncation will not cut off the middle of a word. (Default value is 100.)
Licensing
Kethigallery is licensed under the Creative Commons Attribution 3.0 United States License. You are permitted to redistribute and/or modify this work for commercial or noncommercial purposes provided proper attribution to the original author (me) is present in the redistribution.