News

Random Image for external site

Put the file in your zenphoto/zp-core/random.php

To call from another PHP
@readfile('http://yourgallery.com/zenphoto/zp-core/random.php?
num=9&height=50&width=50&class=one-image')

The above mean return 9 random images which height and width is 50px and the style class is "one-image".

@readfile('http://yourgallery.com/zenphoto/zp-core/random.php?
num=9&height=50&width=50&class=one-image&album=city')

this will only get the random images from album "city"(the parameter is the folder of album).

RSS feed which groups photos

The idea is to group together in the same rss entry all the photos that have been added at the same time in the same album. Photos are browsed by decreasing mtime (=upload date, because id doesn't seem to be very reliable), and every time the album change, or a one hour gap occurred during uploading, a new entry is created. This entry contains the list of all photos with title and description, and optionally photo (?showphotos). RSS entries are not created if the latest photo is less than 1 hour old, in order to avoid multiple entries for the same uploading event (moreover it gives some time to edit titles and descriptions during this hour).

eAccelerator caching

a. Reduce load on the DB server

This is based on the caching technique described on http://www.zenphoto.org/2008/01/hacks/ We'll use eAccelerator shm cache instead of storing the query results on disk.
1. Edit the functions-db.php under zp-core directory.
2. Search function query_single_row, change it to:
function query_single_row($sql, $noerrmsg=false) {
if ($cache = get_cache($sql))
return $cache;
$result = query($sql, $noerrmsg);
if ($result) {
$data = mysql_fetch_assoc($result);
store_cache($sql, $data);
return $data;
}
else {
return false;
}
}

3. Search function query_full_array, change it to:
function query_full_array($sql, $noerrmsg = false) {
if ($cache = get_cache($sql))
return $cache;
$result = query($sql, $noerrmsg);
if ($result) {
$allrows = array();
while ($row = mysql_fetch_assoc($result))
$allrows[] = $row;
(...)

Server side optimization

Database result cache

As we know, the database will use many resource and time to query the information of Image. If we want to save time, we could do optimization with cache the result.
What I use is two functions, you could use other PHP cache library too. The code I use is version 1.13.
!! Please note: because I don't open the comment function, so it may have problem with comment.

1. Edit the functions-db.php under zp-core directory.

2. Search function query_single_row, change it to:
function query_single_row($sql){
if ($cache = get_cache($sql))
return $cache; $result = query($sql);
if ($result) {
$singlerow = mysql_fetch_assoc($result);
store_cache($sql, $singlerow);
return $singlerow;
} else {
return false;
}
}

3. Search function query_full_array, change it to:
function query_full_array($sql){
if ($cache = get_cache($sql)) (...)

Client side optimization

As per yahoo! optimization guidelines http://developer.yahoo.com/yslow/ for making Zenphoto faster at client-side, here are some hacks.

FIRST: Edit .htaccsss file and add the following lines.

<ifmodule mod_expires.c><filesmatch "\.(jpg|gif|png|css|js)$">
ExpiresActive on
ExpiresDefault "access plus 1 year"
</filesmatch>
</ifmodule>FileETag None
That will make your image, javascript,css files cache lifetime 1 year+ and Removes Etags, If Apache WebServer?has attached any. So that webpage header size can be reduced.

SECOND: If your web server is supporting gzip compression, edit index.php and add following line at Top of the page.

header("Vary: Accept-Encoding");if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'))
ob_start("ob_gzhandler");
else ob_start();

So, Web server will (...)

Flickr importer

This script grabs the photos and meta data and creates albums in Zenphoto and entries in the appropriate tables.

e107 autogallery to Zenphoto migration

A tutorial from 2008 to migrated from the autogallery plugin of the CMS e107 to Zenphoto including a Phyton script to migrate the view counter to Zenphoto's hitcounter.

Coppermine to Zenphoto import

A very basic script in Perl that will copy over Metadata from Coppermine to Zenphoto. The data is keyed on filename, so it is assumed that you have unique filenames in your albums.

Import Menalto Gallery 2 Image Descriptions

A Perl script to import Menalto Gallery 2 Image Descriptions.

MWZenphoto - MediaWiki integration

A MediaWiki extension to allow inclusion of images from a Zenphoto gallery using a simple tag in the markup.