View Single Post
Old 10-25-2007, 02:44 PM   #3 (permalink)
Karl
The Reckoner
Advanced Programmer Top Contributor 
 
Karl's Avatar
 
Join Date: Sep 2007
Posts: 437
Thanks: 22
Karl is on a distinguished road
Default

Here's a bit of code for the image part. It could be cleaned up a bit better, but it's enough to get your started and it works (currently only with jpeg)

PHP Code:

<?php

$szImagesDir 
'images/';
$szThumbsDir 'images/thumbs/';

foreach (
glob($szImagesDir '*.{jpg,JPG}'GLOB_BRACE) as $szImagePath)
{
    
$aImagePathParts explode('/'$szImagePath);
    
$szFileName end($aImagePathParts);

    if (!
file_exists($szThumbsDir $szFileName))
    {
        
$pImageHandle imagecreatefromjpeg($szImagePath);

        if (!
$pImageHandle)
        {
            continue;
        }

        
$aSize getimagesize($szImagePath);
        
        
$pNewImageHandle imagecreatetruecolor(6464);
        
        
imagecopyresampled($pNewImageHandle$pImageHandle00006464$aSize[0], $aSize[1]);
        
        
imagejpeg($pNewImageHandle$szThumbsDir $szFileName);        
    }
    
    echo 
'<img src="' $szThumbsDir $szFileName '" />';
}

?>
Simply change the two directory paths at the top to point to your images and thumb folders. The thumbs folder is used to store thumbnails of each image - you'll need to create this.

Hope it helps.
__________________
Any fool can write code that a computer can understand. Good programmers write code that humans can understand.
Karl is offline  
Reply With Quote