我創建腳本來掃描圖像目錄,然後創建縮略圖到另一個目錄。掃描目錄和創建縮略圖圖像
function createThumbs($pathToImages, $pathToThumbs, $thumbWidth)
{
// Turn off all error reporting
error_reporting(0);
set_time_limit(0);
// open the directory
$dir = opendir($pathToImages);
// loop through it, looking for any/all JPG files:
$i='1';
while (false !== ($fname = readdir($dir))) {
// parse path for the extension
$info = pathinfo($pathToImages . $fname);
// continue only if this is a JPEG image
$source_file_name = basename($source_image);
$source_image_type = substr($source_file_name, -3, 3);
switch(strtolower($info['extension']))
{
case 'jpg':
$img = imagecreatefromjpeg("{$pathToImages}{$fname}");
break;
case 'gif':
$img = imagecreatefromgif("{$pathToImages}{$fname}");
break;
case 'png':
$img = imagecreatefrompng("{$pathToImages}{$fname}");
break;
}
echo "$i : Creating thumbnail for small_$fname <br />";
// load image and get image size
$width = imagesx($img);
$height = imagesy($img);
// this will be our cropped image
// copy the crop area from the source image to the blank image created above
// calculate thumbnail size
$new_width = $thumbWidth;
$new_height = $thumbWidth;
// create a new tempopary image
$tmp_img = imagecreatetruecolor($new_width, $new_height);
// copy and resize old image into new image
imagecopyresized($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
switch(strtolower($info['extension']))
{
case 'jpg':
imagejpeg($tmp_img, "{$pathToThumbs}small_$fname", 100);
break;
case 'gif':
imagegif($tmp_img, "{$pathToThumbs}small_$fname");
break;
case 'png':
imagepng($tmp_img,"{$pathToThumbs}small_$fname", 0);
break;
}
imagedestroy($img);
imagedestroy($tmp_img);
$i++;
}
// close the directory
closedir($dir);
}
,我們呼籲與
createThumbs("media/normal/","media/small/",70);
腳本工作做好,但問題是,我有大約4000圖像這些功能,和腳本停在約2400-2600圖像
創建縮略圖你可以試試這個鏈接http://saharandev.co.uk/saharan/create_thumbs_small.php
任何人都可以幫忙嗎?
謝謝
「停止創建」是什麼意思?腳本是否停止執行?沒有迭代這些圖像?執行得很好,但根本不對這些圖像做任何事情?拋出異常?拋出錯誤?一個警告?在哪一行? – Patashu
查看日誌:腳本是否以超時,OOM或其他方式停止? –
@Patashu:我運行腳本,它停在'2335:爲small_S60.10700.jpg創建縮略圖「,我建議刪除'error_reporting(0);'以顯示錯誤。 –