カレンダー
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31       
<<前月 2024年03月 次月>>
最近の記事
過去の記事
カテゴリー
サイト内検索
最近のコメント
リンク
プロフィール
その他
ログイン
現在のモード: ゲストモード
USER ID:
USER PW:
管理ページ
ADMIN ID:
ADMIN PW:
アクセス数
合計:50289
今日:018
昨日:039

GDで投稿時に画像縮小
勤務校のサイトで使えるのはGDなので,以下のサイトを参考に投稿時に画像を縮小するようファイル(admin.php, pict.php)を書き換え


$error = blogn_mod_db_file_add($user_id, $file_name, $comment);
@chmod($dest,0666);
// 最大サイズを超える画像をリサイズする
if ($size = @getimagesize($dest)) {
if ($size[0] > BLOGN_MAXWIDTH || $size[1] > BLOGN_MAXHEIGHT) {
$ratio1 = BLOGN_MAXWIDTH / $size[0];
$ratio2 = BLOGN_MAXHEIGHT / $size[1];
if ($ratio1 < $ratio2) {
$ratio = $ratio1;
}else{
$ratio = $ratio2;
}
$rwidth = round($size[0] * $ratio);
$rheight = round($size[1] * $ratio);
$file_type = strtolower(end(explode('.', $dest)));
if ($file_type === "jpg" || $file_type === "jpeg") {
$in = ImageCreateFromJPEG($dest);
$out = ImageCreateTrueColor($rwidth, $rheight);
ImageCopyResampled($out, $in, 0, 0, 0, 0, $rwidth, $rheight, $size[0], $size[1]);
ImageJPEG($out, $dest, 100);
} elseif ($file_type === "gif") {
$in = ImageCreateFromGIF($dest);
$out = ImageCreateTrueColor($rwidth, $rheight);
ImageCopyResampled($out, $in, 0, 0, 0, 0, $rwidth, $rheight, $size[0], $size[1]);
ImageGIF($out, $dest, 100);
} elseif ($file_type === "png") {
$in = ImageCreateFromPNG($dest);
$out = ImageCreateTrueColor($rwidth, $rheight);
ImageCopyResampled($out, $in, 0, 0, 0, 0, $rwidth, $rheight, $size[0], $size[1]);
imagealphablending($out, false);
imagesavealpha($out, true);
ImagePNG($out, $dest, 9);
} else {
return;
}
ImageDestroy($in);
ImageDestroy($out);
}
}



| http://freeside.skr.jp/blognplus/index.php?e=8 |
| ブログ::BlognPlus | 04:47 PM | comments (0) | trackback (0) |

PAGE TOP ↑