【问题标题】:PHP Gallery with lightbox, folder import and descriptions from file names带有灯箱、文件夹导入和文件名描述的 PHP Gallery
【发布时间】:2016-04-26 09:06:46
【问题描述】:

有没有具有三个特点的画廊:

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

我必须在昨天完成 :)

【问题讨论】:

    标签: php import directory gallery lightbox


    【解决方案1】:

    我已经制作了自己的脚本和原始灯箱 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 Image Viewer 一次性批量调整图像大小并创建微缩模型。在应用程序中只需按 F3 即可打开高级处理工具。

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

    总体效果不错 - 我在网站上的某个地方隐藏了脚本,并在 1.5 小时内生成了 6 个包含约 1.5k 张图片的画廊,并且大部分时间都花在了文件处理和复制上。不优雅但有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-13
      • 2016-02-27
      • 2017-01-25
      • 1970-01-01
      相关资源
      最近更新 更多