PHP 图库,带有灯箱、文件夹导入和文件名说明


PHP Gallery with lightbox, folder import and descriptions from file names

是否有具有三个功能的图库:

  • 在灯箱中显示图片
  • 允许从一个文件夹中一次导入数十或数百张图像
  • 从文件名中获取说明

我必须在昨天:)

我用

原始灯箱一起制作了自己的脚本http://lokeshdhakar.com/projects/lightbox2/决定这样会快得多:

        <?php
            echo str_replace(array('<','>'), array('&lt;','&gt;'),'<table id="galx"><tr>');
            $source_dir = 'images/taken/from/here';
            $mini_dir = 'mini';
            $target_dir = 'imagies/copied/to/there';
            $i=0;
            $images = array_diff(scandir($source_dir), array('..', '.',$mini_dir));
            foreach($images as $image)
            {
                $filename = pathinfo($image, PATHINFO_FILENAME);
                $title = mb_strtoupper(trim(str_replace('_',' ',$filename)));
                $s = "<td><a href='$target_dir/$image' data-lightbox='galx' data-title='$title' >"
                        . "<img src='$target_dir/$mini_dir/$filename.jpg' /><br/>"
                        . "$title<a/></td>";  //gallery with titles
                /*$s = "<td><a href='$target_dir/$image' data-lightbox='galx' >"
                        . "<img src='$target_dir/$mini_dir/$filename.jpg' />"
                        . "<a/></td>";*/ //gallery without titles
                if (++$i % 5 == 0)
                    $s .= '</tr><tr>';
                $s = str_replace(array('<','>'), array('&lt;','&gt;'), $s); //comment this line if want to paste it as php code
                echo $s;
            }
            echo str_replace(array('<','>'), array('&lt;','&gt;'),'</tr></table>');
        ?>

一些基本的 css:

#galx {
  width: 650px;
}
#galx td {
    text-align: center;
}
#galx a {
    display: block;
    width: 120px;
    font-size: 0.8em;
    margin:1px auto;
    text-decoration: none;
    color: black;
    text-align: center;
}

我使用FastStone图像查看器一次批量调整图像大小并创建微缩模型。在应用程序中,只需按F3即可打开高级处理工具。

它只是不适用于Windows - PHP错误上的非英语字母。它仍然破坏了 Linux 上文件名的第一个非英文字母,因此在这种情况下需要前缀"_"。

总体上不错的结果 - 我在网站上的某个地方隐藏了脚本,并在 1,5 小时内生成了 6 个带有 ~1,5k 图片的画廊,大部分时间都用于文件处理和复制。不优雅但有效。