-3

私は php 画像ギャラリーを作成しています。長い検索の後、Google で適切な php 画像ギャラリー コードを見つけました。画像のサムネイルをクリックすると、元の画像の場所に送信されますが、元の画像の代わりに、同じ画像が表示される別のページにユーザーを送信したい!

これがコードです!

<?php   # SETTINGS


        $max_width = 200;
        $max_height = 200;
        $per_page = 9;

        $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);
        }
    ?>

申し訳ありませんが、私の英語は苦手です。私の質問を理解していただければ幸いです。

4

1 に答える 1

2

このコードには、画像リンクに rel="lightbox['.$lightbox.'] が含まれています。ブラウザで Lightbox を使用して画像を表示することを想定しています。Lightbox は JavaScript ライブラリです (クローンもたくさんあります)。既存のページの上に画像を表示し、背景を灰色にします. これはかなりいいです. Lightbox を使用して画像を表示することを検討することをお勧めします.

それ以外の場合は、次の行を変更する必要があります。

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

URL の GET 値として $file を使用して、href が必要なページを指すようにします。使用しない場合は、rel= を削除する必要があります。害はありませんが、ライトボックスを使用しないと散らかってしまいます。たとえば、次のようなものです。

echo '<li><a href="display.php?image='.$file.'">';

ここで、display.php は画像を表示するページです。

于 2013-01-01T20:53:44.783 に答える