1

我不知道如何使用 phpThumb 类生成缩略图,其中包含一个包含文件路径的数组。然后将每个图像的结果保存在其他路径但名称相同。

谢谢你们 ;)

编辑:我的代码是这样的:

    echo "A iniciar gerador de miniaturas para a área de cliente: \n";
    include $wincli['files']['phpThumbClass'];
    $files = file_list($wincli['dirs']['logos']);

    $phpThumb = new phpThumb();
    foreach( $files as $file ) {
        echo "  # A converter o ficheiro '".basename($file)."' : ";
        if(is_file($file)){         
            $phpThumb->setSourceFilename($file); 
            $phpThumb->setParameter('w', 880);
            $phpThumb->setParameter('h', 241);
            $phpThumb->setParameter('q', 90);
            $phpThumb->setParameter('zc', 1);
            $outputFilename = $wincli['dirs']['logosthumbs'].$file;

            if($phpThumb->GenerateThumbnail()){
                if($phpThumb->RenderToFile($outputFilename)){
                    echo "OK \n";
                }else{
                    echo "Falhou (Ao guardar no ficheiro)\n";
                }
            }else{
                echo "Falhou (Ao gerar miniatura)\n";
            }
        }else{
            echo "Falhou (Ficheiro inexistente)\n";
        }
    }

这是调试:

phpThumb() v1.7.7-200612252156 in file "phpthumb.class.php" on line 216
setSourceFilename(/var/www/virtual/test.com/wincli/logos/001-0.jpg) set $this->sourceFilename to "/var/www/virtual/test.com/wincli/logos/001-0.jpg" in file "phpthumb.class.php" on line 234
  file_exists() = 0 in file "phpthumb.class.php" on line 1036
is_executable() = 0 in file "phpthumb.class.php" on line 1037
ImageMagickThumbnailToGD() aborting because cannot find convert in $this->config_imagemagick_path (), and `which convert` returned () in file "phpthumb.class.php" on line 1066
$AvailableImageOutputFormats = array(text;ico;bmp;wbmp;gif;png;jpeg) in file "phpthumb.class.php" on line 825
$this->thumbnailFormat set to $this->config_output_format "jpeg" in file "phpthumb.class.php" on line 835
$this->thumbnailQuality set to "90" in file "phpthumb.class.php" on line 852
!$this->config_allow_src_above_docroot therefore setting "/var/www/virtual/test.com/wincli/logos/001-0.jpg" (outside "/var/www/virtual/test.com/htdocs") to null in file "phpthumb.class.php" on line 1001
$this->sourceFilename set to "" in file "phpthumb.class.php" on line 754
phpThumb() v1.7.7-200612252156

"" does not exist in file "phpthumb.class.php" on line 3404
setCacheDirectory() starting with config_cache_directory = "" in file "phpthumb.class.php" on line 859
$this->config_cache_directory () is not a directory in file "phpthumb.class.php" on line 895
SetCacheFilename() failed because $this->config_cache_directory is empty in file "phpthumb.class.php" on line 2808
starting ExtractEXIFgetImageSize() in file "phpthumb.class.php" on line 2665
GetImageSize("") failed in file "phpthumb.class.php" on line 2688
$this->useRawIMoutput=false because "fltr" is set in file "phpthumb.class.php" on line 1151
ImageMagickThumbnailToGD() aborting because $this->sourceFilename is empty in file "phpthumb.class.php" on line 1196
ImageMagickThumbnailToGD() failed in file "phpthumb.class.php" on line 2695
SetOrientationDependantWidthHeight() starting with ""x"" in file "phpthumb.class.php" on line 2644
SetOrientationDependantWidthHeight() setting w="880", h="241" in file "phpthumb.class.php" on line 2660
EXIF thumbnail extraction: (size=0; type=""; 0x0) in file "phpthumb.class.php" on line 2747
starting SourceImageToGD() in file "phpthumb.class.php" on line 3005
$this->useRawIMoutput=false because "fltr" is set in file "phpthumb.class.php" on line 1151
ImageMagickThumbnailToGD() aborting because $this->sourceFilename is empty in file "phpthumb.class.php" on line 1196
Not using EXIF thumbnail data because $this->exif_thumbnail_data is empty in file "phpthumb.class.php" on line 3046
$this->gdimg_source is still empty in file "phpthumb.class.php" on line 3098
ImageMagickThumbnailToGD() failed in file "phpthumb.class.php" on line 3100
phpThumb() v1.7.7-200612252156

Unknown image type identified by "" () in SourceImageToGD()[3210] in file "phpthumb.class.php" on line 3404
SourceImageToGD() failed in file "phpthumb.class.php" on line 312
4

3 回答 3

6
$files = array('filename.jpg', 'filename2.jpg');
foreach( $files as $file ) { // here's part 1 of your answer
   $phpThumb->setSourceFilename($file); 
   $phpThumb->setParameter('w', 100);
   $outputFilename = "thumbs/".$file;

    if ($phpThumb->GenerateThumbnail()) { 
        if ($phpThumb->RenderToFile($outputFilename)) { // here's part 2 of your answer
           // do something on success
        } else {
           //failed
        }
    } else {
        // failed
    }
}

有关更多信息,请参阅http://phpthumb.sourceforge.net/index.php?source=demo%2FphpThumb.demo.object.php

于 2010-05-25T18:00:17.213 回答
2

修复错误。

    echo "A iniciar gerador de miniaturas para a área de cliente: \n";
    include $wincli['files']['phpThumbConfig'];
    include $wincli['files']['phpThumbClass'];
    $files = file_list($wincli['dirs']['logos']);

    echo "A gerar novas miniaturas: \n";

    foreach( $files as $file ) {
        if(
            (strtolower(get_file_extension($file))=="jpg") ||
            (strtolower(get_file_extension($file))=="jepg") ||
            (strtolower(get_file_extension($file))=="bmp") ||
            (strtolower(get_file_extension($file))=="png")
        ){
            echo "  -> ".basename($file)." : ";
            if(is_file($file)){
                $phpThumb = new phpThumb();
                $phpThumb->setSourceFilename($file);
                $phpThumb->setParameter('config_output_format', 'jpeg');
                $phpThumb->setParameter('config_allow_src_above_docroot', true);
                $phpThumb->setParameter('w', 880);
                $phpThumb->setParameter('h', 241);
                $phpThumb->setParameter('q', 90);
                $phpThumb->setParameter('zc', 1);
                $phpThumb->setParameter('config_cache_directory', $wincli['dirs']['phpThumbCache']);
                $phpThumb->setParameter('config_temp_directory', $wincli['dirs']['phpThumbCache']);
                $phpThumb->setParameter('config_cache_disable_warning', true);
                $phpThumb->setParameter('config_imagemagick_path', null);
                $phpThumb->setParameter('config_prefer_imagemagick', false);
                $outputfile = $wincli['dirs']['logosthumbs'].basename($file);

                if($phpThumb->GenerateThumbnail()){
                    if($phpThumb->RenderToFile($outputfile)){
                        echo "OK \n";
                    }else{
                        echo "Falhou (Ao guardar no ficheiro)\n";
                    }
                }else{
                    echo "Falhou (Ao gerar miniatura)\n";
                }
            }else{
                echo "Falhou (Ficheiro inexistente?)\n";
            }
        }
    }
于 2010-05-28T15:21:03.127 回答
2

我在 Strato 服务器上遇到了问题,使它起作用的是以下行:

$phpThumb->setParameter('config_allow_src_above_docroot', true);
于 2010-11-16T09:32:53.363 回答