UBB.Dev
Posted By: DrChaos Question about this code... - 01/12/2005 5:02 AM
This is a script that will show the images in a folder as thumbnails and when you click the thumbnails it will open the original image. The thing im tring to get it to do is when the thumbnail is clicked it will open the image in a new window not the same one. I would also like to add the "close this window" link too. Ill never be able to afford PhotoPost so this is what i have to use. If you take this code and call it index.php and place it into a folder with images you can see what it does.



Code
<?<br />if( ! isset( $filename ) ){<br />define( "SIZE" , 120 ) ;<br />define( "COLNUM" , 5 ) ;<br />$dir = ($dir)?$dir:"." ;<br />?><br /><html><br /><head><br /><title>Our Pictures <?= $dir ?></title><br /><style type="text/css"><br /><!--<br />table{<br />width:100%;<br />}<br />td{<br />text-align:center;<br />}<br />img{<br />border:none;<br />}<br />--><br /></style><br /></head><br /><body><br /><table><br /><?<br />$dd = opendir($dir) ;<br /><br />for( $i = 0 ; $filename = readdir($dd) ; ){<br />if( is_file("$dir/$filename") ){<br />if( $imgSize = getImageSize("$dir/$filename") ){<br /><br />$w0 = $imgSize[0] ;<br />$h0 = $imgSize[1] ;<br /><br />$imgType = $imgSize[2] ;<br /><br />$ratio = $w0 / $h0 ;<br /><br />if( $ratio > 1 ){<br />$w1 = SIZE ;<br />$h1 = ( SIZE * $h0 ) / $w0 ;<br />}<br />else{<br />$w1 = ( SIZE * $w0 ) / $h0 ;<br />$h1 = SIZE ;<br />}<br /><br />$params = sprintf( "filename=$dir/$filename&w0=$w0&h0=$h0&imgType=$imgType&h1=%d&w1=%d" , $h1 , $w1 ) ;<br /><br />if( ! ( $i % COLNUM ) ){<br />echo "\n<tr>\n" ;<br />}<br />?><br /><td><br /><a href="<?= "$dir/$filename" ?>"><br /><img src="<?= $filename ?>?<?= $params ?>" style="width:<?= $w1 ?>;height:<?= $h1 ?>;"></a><br><br /><?= "$filename : $w0 x $h0" ?><br /><?<br />$i++ ;<br />}<br />}<br />}<br />?><br /></table><br /></body><br /></html><br /><?<br />closedir($dd) ;<br />}<br />else{<br />switch($imgType){<br />case 1:<br />$imgType = "gif" ;<br />break;<br /><br />case 2:<br />$imgType = "JPEG" ;<br />break;<br /><br />case 3:<br />$imgType = "png" ;<br />break;<br /><br />default:<br />break;<br />}<br />header("Content-type: image/$imgType") ;<br /><br />$tImg = imageCreate( $w1 , $h1 ) ;<br /><br />$imgOpenFunc = "imageCreateFrom".$imgType ;<br />$imgSendFunc = "image".$imgType ;<br /><br />$img = $imgOpenFunc("$filename") ;<br /><br />imageCopyResized( $tImg , $img , 0 , 0 , 0 , 0 , $w1 , $h1 , $w0 , $h0 ) ;<br /><br />imageDestroy($img) ;<br /><br />$imgSendFunc($tImg) ;<br />}<br />?><br />  
Posted By: JoshPet Re: Question about this code... - 01/12/2005 7:49 AM
For a new window - changing this line:

<a href="<?= "$dir/$filename" ?>">

To this:


<a href="<?= "$dir/$filename" ?>" target="_blank">


Should do it.
Posted By: DrChaos Re: Question about this code... - 01/12/2005 6:32 PM
bah, I was close. I was adding it like this <a href="<?= "$dir/$filename" ?>" target=_blank">

Thanks again for the help Josh....
© UBB.Developers