0

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

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

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

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
4

1 回答 1

2

尝试

$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 ();
    }
}
于 2012-04-26T19:24:14.483 回答