php博客风格画廊

时间:2013-01-01 11:13:23

标签: php

经过长时间搜索谷歌后我发现下面的图像库的PHP代码,但它产生jquery效果后,缩略图,而不是jquery我想去其他页面,显示完整的相应图像,像一个wordpress博客呢!

<?php
    # SETTINGS
    $max_width = 200;
    $max_height = 200;
    $per_page = 9;
    //$imagedir = 'gallery/';
    $page = $_GET['page'];

    $has_previous = false;
    $has_next = false;

    function getPictures() {
        global $page, $per_page, $has_previous, $has_next;
        if ( $handle = opendir(".") ) {
            $lightbox = rand();
            echo '<ul id="pictures">';

            $count = 0;
            $skip = $page * $per_page;

            if ( $skip != 0 )
                $has_previous = true;

            while ( $count < $skip && ($file = readdir($handle)) !== false ) {
                if ( !is_dir($file) && ($type = getPictureType($file)) != '' )
                    $count++;
                    }

            $count = 0;
            while ( $count < $per_page && ($file = readdir($handle)) !== false ) {
                if ( !is_dir($file) && ($type = getPictureType($file)) != '' ) {
                    if ( ! is_dir('thumbs') ) {
                        mkdir('thumbs');
                    }
                    if ( ! file_exists('thumbs/'.$file) ) {
                        makeThumb( $file, $type );
                    }
                    echo '<li><a href="'.$file.'" rel="lightbox['.$lightbox.']">';

                    echo '<img src="thumbs/'.$file.'" alt="" />';

                    echo '<div class="fb">view</div></a></li>';


                    $count++;

                }

            }

            echo '</ul>';

            while ( ($file = readdir($handle)) !== false ) {
                if ( !is_dir($file) && ($type = getPictureType($file)) != '' ) {
                    $has_next = true;
                    break;
                }
            }
        }
    }

    function getPictureType($file) {
        $split = explode('.', $file); 
        $ext = $split[count($split) - 1];
        if ( preg_match('/jpg|jpeg/i', $ext) ) {
            return 'jpg';
        } else if ( preg_match('/png/i', $ext) ) {
            return 'png';
        } else if ( preg_match('/gif/i', $ext) ) {
            return 'gif';
        } else {
            return '';
        }
    }

    function makeThumb( $file, $type ) {
        global $max_width, $max_height;
        if ( $type == 'jpg' ) {
            $src = imagecreatefromjpeg($file);
        } else if ( $type == 'png' ) {
            $src = imagecreatefrompng($file);
        } else if ( $type == 'gif' ) {
            $src = imagecreatefromgif($file);
        }
        if ( ($oldW = imagesx($src)) < ($oldH = imagesy($src)) ) {
            $newW = 220;
            $newH = $max_height;
        } else {
            $newW = $max_width;
            $newH = 200;
        }
        $new = imagecreatetruecolor($newW, $newH);
        imagecopyresampled($new, $src, 0, 0, 0, 0, $newW, $newH, $oldW, $oldH);
        if ( $type == 'jpg' ) {
            imagejpeg($new, 'thumbs/'.$file);
        } else if ( $type == 'png' ) {
            imagepng($new, 'thumbs/'.$file);
        } else if ( $type == 'gif' ) {
            imagegif($new, 'thumbs/'.$file);
        }
        imagedestroy($new);
        imagedestroy($src);
    }
?>

1 个答案:

答案 0 :(得分:0)

从输出图像的rel循环中的anchor元素中删除while属性。这会阻止Lightbox脚本将事件绑定到此链接,因此当用户单击它时,它们将被简单地重定向到href属性中指定的图像。

换句话说,而不是

echo '<li><a href="'.$file.'" rel="lightbox['.$lightbox.']">';

使用

echo '<li><a href="'.$file.'">';