如何使用phpthumb(或其他一些库)自动将整个目录复制为缩略图 [英] how to automatically copy an entire directory as thumbnails using phpthumb (or some other library)

查看:137
本文介绍了如何使用phpthumb(或其他一些库)自动将整个目录复制为缩略图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望将放置在目录中的所有图像复制为单独的目录作为缩略图,然后可以在我的网站上查看.现在,我正在研究phpthumb,但也下载了wideimage和zen照片.

I would like all images dropped in a directory to be copied into a separate directory as thumbnails that i can then view on my site. Right now i'm researching phpthumb, but have also downloaded wideimage and zen photo.

感谢您能找到与此完全相同的副本,相近的匹配也可能会有所帮助.

Thanks if you can find an exact duplicate to this, near matches may also be helpful.

以下是仅复制单个文件的脚本:

Here is the script that only copies a single files:

require_once '../ThumbLib.inc.php';
//include the thumb library 
$thumb = PhpThumbFactory::create('test.jpg');
//create a new image from the targeted jpegs
$thumb->adaptiveResize(100, 100);
//resize 
$thumb->save('test.png', 'png');
//save as 'test' with the file type png
//echo "<img src='$thumb' class='thumb'>";
$thumb->show();
//print the thumbnail to the screen

推荐答案

尝试

$dir = "photos" ;
$destination = "thumb" ;
$images = scandir($dir);

foreach ( $images as $image ) {

    if(is_file($image))
    {
        $ext = pathinfo ( $dir . DIRECTORY_SEPARATOR . $image, PATHINFO_EXTENSION );
        $thumb = PhpThumbFactory::create ( $dir . DIRECTORY_SEPARATOR . $image );
        $thumb->adaptiveResize ( 100, 100 );
        $thumb->save ( $destination . DIRECTORY_SEPARATOR . $image, $ext );
        $thumb->show ();
    }
}

这篇关于如何使用phpthumb(或其他一些库)自动将整个目录复制为缩略图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆