任何人都可以在這裏找到我要去的地方。它應該在一個文件夾中創建圖像的灰度副本並將其保存在另一個文件夾中。這可能與我引用文件位置的方式有關。兩個文件夾上的文件夾權限均爲777.腳本運行時沒有可見的錯誤,但沒有創建圖像。使用php將圖像批處理文件夾變成灰度
function grayscalecopy($targetfile, $outputfile){
$size = GetImageSize($targetfile);
$width = $size[1];
$height = $size[0];
$canvas = imagecreatetruecolor($width, $height);
$sourceimage = imagecreatefromjpeg($targetfile);
imagefilter($sourceimage, IMG_FILTER_GRAYSCALE);
imagecopy($canvas, $sourceimage, 0, 0, 0, 0, $width, $height);
imagejpeg($canvas, $outputfile, 95);
imagedestroy($sourceimage);
imagedestroy($canvas);
echo "Converted ".$targetfile." to grayscale as ".$outputfile." ".$width."x".$height."<br/>";
}
$serverfiles = glob("artworkimages/thumbs/*.*");
//$numbertocache = count($serverfiles);
$numbertocache = 10;
for ($i=0; $i<$numbertocache; $i++)
{
$serverfilesshort=explode("/",$serverfiles[$i]);
$serverfilesshort=$serverfilesshort[count($serverfilesshort)-1];
grayscalecopy($serverfiles[$i], "artworkimages/thumbs/grays/".$serverfilesshort);
}
您看到的具體問題是什麼?請編輯您的答案並描述問題。 – Josh 2010-03-12 14:35:30
腳本運行時沒有可見的錯誤,但沒有創建圖像。 – James 2010-03-12 14:38:40
您是否在輸出中看到許多「將xxx轉換爲灰度爲yyy 123x456」行? – Josh 2010-03-12 15:59:24