
/****************************************
生成済みサムネイル一覧取得
****************************************/
// サムネイル画像名格納配列
$aThumbList = array();
// サムネイルディレクトリを開く
if($handlerDir = @OpenDir("./thumb")){
// ディレクトリ内のファイルを取り出す
while($sThumbName = ReadDir($handlerDir)){
if($sThumbName != "." && $sThumbName != ".."){
// 配列に画像名を追加
$aThumbList[] = $sThumbName;
}
}
}
CloseDir($handlerDir);
/****************************************
ログを読み込み、サムネイルが生成済みかチェック
****************************************/
// ログファイル読み込み
$fp = fopen("http://test:test@natsu-nikki2009.petit.cc/1log/log_lime.txt", "r");
if ($fp == false) {
printf("ファイルを開けませんでした。\n");
return;
}
$count = 0;
$aLogList = array();
while (!feof($fp)) {
// 読み込み
$strs[$count] = fgets($fp);
$aArticle = split(",", $strs[$count]);
if($aArticle[7] != 1 && $aArticle[1] != ''){
// サムネイルが生成済みの場合
if(In_Array($aArticle[1], $aThumbList)){
// 処理なし
}else{
// サムネイルを生成
CreateThumbImage($aArticle[1]);
}
}
// ログリストに追加
$aLogList[] = $aArticle;
$count++;
}
fclose($fp);
/****************************************
サムネイル表示領域のHTML生成
****************************************/
$gaWeek = array(
'Sun' => '日',
'Mon' => '月',
'Tue' => '火',
'Wed' => '水',
'Thu' => '木',
'Fri' => '金',
'Sat' => '土'
);
for ($iCnt = 0; $iCnt < count($aLogList); $iCnt++){
switch($aLogList[$iCnt][4]){
case 'k' : $aAuthor = 'ico_k'; break; // ヨシダ
case 'm' : $aAuthor = 'ico_m'; break; //
case 'j' : $aAuthor = 'ico_j'; break; //
case 'h' : $aAuthor = 'ico_h'; break; //
case 't' : $aAuthor = 'ico_t'; break; //
case 's' : $aAuthor = 'ico_s'; break; //
default : $aAuthor = 'ico_other'; //
}
$aPostDate = split("[(./.)]", $aLogList[$iCnt][0]);
$sArticleDate = $aPostDate[1] . "月" . $aPostDate[2] . "日(" . $gaWeek[$aPostDate[4]] . ")";
if($aLogList[$iCnt][7] != 1 && $aLogList[$iCnt][1] != ''){
// サムネイルを表示
print "

\n";
print "
\n\n";
}
}
/****************************************
サムネイル画像の生成
****************************************/
function CreateThumbImage($img_name){
// サムネイルを作る元画像のあるディレクトリ(必ず末尾は"/"で閉じる)
$img_path = "http://test:test@natsu-nikki2009.petit.cc/1img/lime_img/";
// サムネイルサイズ
$thumbnail_size = 130;
// サムネイルを保存するディレクトリ
$thumbnail_path = "thumb/";
// 元画像のサイズ取得
$aImgState = @getimagesize($img_path.$img_name);
//元の画像の横幅
$img_w = $aImgState[0];
//元の画像の縦幅
$img_h = $aImgState[1];
//サムネイル元
$src_img = @imagecreatefromjpeg ( $img_path.$img_name );
if( $src_img ){
//サムネイル作成
$dst_img = imagecreatetruecolor ( $thumbnail_size, $thumbnail_size );
// 短辺に合わせてトリミング開始位置と長さを算出
if($img_w > $img_h){
$nSrcPointX = ($img_w - $img_h) / 2;
$nSrcPointY = 0;
$nSrcWidth = $nSrcHeight = $img_h;
}else{
$nSrcPointX = 0;
$nSrcPointY = ($img_h - $img_w) / 2;
$nSrcWidth = $nSrcHeight = $img_w;
}
$result = imagecopyresampled( $dst_img, $src_img, 0, 0, $nSrcPointX, $nSrcPointY, $thumbnail_size, $thumbnail_size, $nSrcWidth, $nSrcHeight );
/*
$dst_img, //貼り付けするイメージID
$src_img, //コピーする元になるイメージID
0, //int dstX (貼り付けを開始するX座標)
0, //int dstY (貼り付けを開始するY座標)
0, //int srcX (コピーを開始するX座標)
0, //int srcY (コピーを開始するY座標)
$thumbnail_w, //int dstW (貼り付けする幅)
$thumbnail_h, //int dstH (貼り付けする高さ)
$img_w, //int srcW (コピーする幅)
$img_h //int srcH (コピーする高さ)
*/
//サムネイルをJPEG形式で保存
imagejpeg ( $dst_img, $thumbnail_path.$img_name, 90 );
imagedestroy ( $dst_img ); //サムネイル用イメージIDの破棄
imagedestroy ( $src_img ); //サムネイル元イメージIDの破棄
}else{
//error
}
}
?>