How to Update photoalbum

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
manojsemwal1
Forum Contributor
Posts: 217
Joined: Mon Jun 29, 2009 4:13 am
Location: India

How to Update photoalbum

Post by manojsemwal1 »

hai i am designing a dynamic photo album php page using thumbnail to see the image. in their user can create album and put the photo inside the album folder.
its working fine but when i upload photo again in same album, its upload photo in album folder . but not creating thumnail.

dynamically two folder are create
1-$pathToImage=/where photo to be upload//inside this folder 2-folder has create.
2-$pathToThumbs=/where photo will save after thumb /

code are like:

function createThumbs( $pathToImages, $pathToThumbs, $thumbWidth )
{
// open the directory

//echo $pathToImages;
$dir = opendir( $pathToImages );
echo "Directory handle: $dir\n";

// loop through it, looking for any/all JPG files:
while (false !== ($fname = readdir( $dir )))
{
// parse path for the extension
$info = pathinfo($pathToImages . $fname);
// continue only if this is a JPEG image
if ( strtolower($info['extension']) == 'jpg' )
{
echo "Creating thumbnail for {$fname} <br />";

// load image and get image size
$img = imagecreatefromjpeg( "{$pathToImages}{$fname}" );
$width = imagesx( $img );
$height = imagesy( $img );

// calculate thumbnail size
$new_width = $thumbWidth;
$new_height = floor( $height * ( $thumbWidth / $width ) );

// create a new tempopary image
$tmp_img = imagecreatetruecolor( $new_width, $new_height );

// copy and resize old image into new image
imagecopyresized( $tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height );

// save thumbnail into a file
imagejpeg( $tmp_img, "{$pathToThumbs}{$fname}" );
imagedestroy($tmp_img);
imagedestroy($img);
}
}
// close the directory
closedir( $dir );
}

createThumbs($d."/",$dt."/",100);


}
?>
Post Reply