How to Update photoalbum
Posted: Tue Aug 03, 2010 8:42 am
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);
}
?>
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);
}
?>