Wednesday, March 18, 2009

PHP Image Gallery & Truncate a string in Smarty

PHP Image Gallery

This is an image gallery script that allows you to simply upload new full sized images in FTP and the script will automatically create the thumbnails for those images and add those images to a paged thumbnail gallery suitable for browsing.

First of you have to set the variables in the code below.
  1. Scroll down to about line 30 and look for $config['size']. Set this to the maximum width or height you want your image thumbnail to be.
  2. On the next line in the $config['imagequality'] set this to the JPEG quality you would like your thumbnails to be. I recommend you keep it set to 70.
  3. $config['rows'] and $config['cols'] are the number of rows and number of columns of thumbnail images you want shown on each page.
  4. $config['maxShow'] is the number of page numbers to show at one time. for instance if you have 100 pages of images, you can set this to only show the page numbers of the 10 pages close to where you currently are.
  5. $config['thumbs'] is the relative path to where you want the thumbnail images to be stored. Include the trailing slash.

File Permissions:

  1. You'll need to change the permission on the directory you set $config['thumbs'] to. CHMOD it to 775 or 777 so PHP and GD2 can automatically write and create your thumbnails in that directory.

Changing the Look:

  1. The entire gallery table is controlled by the CSS settings you'll find toward the bottom of the gallery.php file. I tried to comment each specific part of the CSS and what it controls so you can easily change the look of the gallery without actually having to actually edit any of the PHP.

Here is the Code:

You can download the gallery.php file from the following link.

Truncate a string in Smarty

Suppose you have a sentense in smarty that contains more characters and the rows of the table where you wants to show it will become wrap which sounds very bad. So you can use smarty variable modifier called 'truncate'.

How to use Truncate:

It has following syntaxes,
$yourString = "Hello World";
  1. {$yourString|truncate}//output// Hello World
  2. {$articleTitle|truncate:3}//output// Hel...
  3. {$articleTitle|truncate:3:""}//output// Hel
  4. {$articleTitle|truncate:3:"---"}//output// Hel---
You can also find more detail from
Special Thanks:
Ihsanuilah Khan

No comments: