Skip to content

Commit

Permalink
change calculation method of GD memory usage in check_memory4gd()
Browse files Browse the repository at this point in the history
  • Loading branch information
nao-pon committed Apr 28, 2013
1 parent 5382725 commit ce536ac
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions xoops_trust_path/class/hyp_common/hyp_common_func.php
Expand Up @@ -504,9 +504,9 @@ function make_thumb($o_file, $s_file, $max_width, $max_height, $zoom_limit="1,95
}
else
{
if (!HypCommonFunc::check_memory4gd($org_w,$org_h))
if (!HypCommonFunc::check_memory4gd($org_w,$org_h,$zoom))
{
// メモリー制限に引っ掛かりそう。(マージン 1MB)
// メモリー制限に引っ掛かりそう。
return $o_file;
}
return HypCommonFunc::make_thumb_gd($o_file, $s_file, $zoom, $quality, $size[2], $org_w, $org_h);
Expand Down Expand Up @@ -991,7 +991,7 @@ function gdVersion($user_ver = 0)
return $match[0];
}

function check_memory4gd($w,$h)
function check_memory4gd($w,$h,$zoom = 1)
{
// GDで処理可能なメモリーサイズ
static $memory_limit = NULL;
Expand All @@ -1001,16 +1001,20 @@ function check_memory4gd($w,$h)
}
if ($memory_limit)
{
// ビットマップ展開時のメモリー上のサイズ
$bitmap_size = $w * $h * 3 + 54;
$sw = $w * $zoom;
$sh = $h * $zoom;
// GD で利用するメモリ量の計算
// @author Mocchi (http://sakamocchi.jp/item/277)
$gd_size = ($sw * $sh * 5 + $sh * 24 + 10000)
+ ($w * $h * 5 + $h * 24 + 10000);

$now_use_mem = intval(memory_get_usage(true));
if (!$now_use_mem) {
$now_use_mem = 4 * 1024 * 1024;
$now_use_mem = 8 * 1024 * 1024; // おおよそ 8MB 使用済みと仮定
}
if ($bitmap_size > ($memory_limit - $now_use_mem - (1 * 1024 * 1024)))
if ($gd_size > ($memory_limit - $now_use_mem ))
{
// メモリー制限に引っ掛かりそう。(マージン 1MB)
// メモリー制限に引っ掛かりそう。
return false;
}
}
Expand Down

0 comments on commit ce536ac

Please sign in to comment.