only one copy of get_memory_limit...

git-svn-id: file:///home/shish/svn/shimmie2/trunk@9 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
shish 2007-04-24 19:12:05 +00:00
parent 65be47dbb7
commit b1b2edf021
3 changed files with 25 additions and 46 deletions

View file

@ -106,28 +106,6 @@ class ImageIO extends Extension {
return imagejpeg($thumb, $outname, $config->get_int('thumb_quality')); return imagejpeg($thumb, $outname, $config->get_int('thumb_quality'));
} }
private function get_memory_limit() {
global $config;
// thumbnail generation requires lots of memory
$default_limit = 8*1024*1024;
$shimmie_limit = parse_shorthand_int($config->get_int("thumb_gd_mem_limit"));
if($shimmie_limit < 3*1024*1024) {
// we aren't going to fit, override
$shimmie_limit = $default_limit;
}
ini_set("memory_limit", $shimmie_limit);
$memory = parse_shorthand_int(ini_get("memory_limit"));
// changing of memory limit is disabled / failed
if($memory == -1) {
$memory = $default_limit;
}
return $memory;
}
private function get_thumb($tmpname) { private function get_thumb($tmpname) {
global $config; global $config;
@ -139,7 +117,7 @@ class ImageIO extends Extension {
$max_height = $config->get_int('thumb_height'); $max_height = $config->get_int('thumb_height');
$memory_use = (filesize($tmpname)*2) + ($width*$height*4) + (4*1024*1024); $memory_use = (filesize($tmpname)*2) + ($width*$height*4) + (4*1024*1024);
$memory_limit = $this->get_memory_limit(); $memory_limit = get_memory_limit();
if($memory_use > $memory_limit) { if($memory_use > $memory_limit) {
$thumb = imagecreatetruecolor($max_width, min($max_height, 64)); $thumb = imagecreatetruecolor($max_width, min($max_height, 64));

View file

@ -65,6 +65,29 @@ function to_shorthand_int($int) {
} }
} }
function get_memory_limit() {
global $config;
// thumbnail generation requires lots of memory
$default_limit = 8*1024*1024;
$shimmie_limit = parse_shorthand_int($config->get_int("thumb_gd_mem_limit"));
if($shimmie_limit < 3*1024*1024) {
// we aren't going to fit, override
$shimmie_limit = $default_limit;
}
ini_set("memory_limit", $shimmie_limit);
$memory = parse_shorthand_int(ini_get("memory_limit"));
// changing of memory limit is disabled / failed
if($memory == -1) {
$memory = $default_limit;
}
return $memory;
}
function bbcode2html($text) { function bbcode2html($text) {
$text = trim($text); $text = trim($text);
$text = html_escape($text); $text = html_escape($text);

View file

@ -83,28 +83,6 @@ class RegenThumb extends Extension {
return imagejpeg($thumb, $outname, $config->get_int('thumb_quality')); return imagejpeg($thumb, $outname, $config->get_int('thumb_quality'));
} }
private function get_memory_limit() {
global $config;
// thumbnail generation requires lots of memory
$default_limit = 8*1024*1024;
$shimmie_limit = parse_shorthand_int($config->get_int("thumb_gd_mem_limit"));
if($shimmie_limit < 3*1024*1024) {
// we aren't going to fit, override
$shimmie_limit = $default_limit;
}
ini_set("memory_limit", $shimmie_limit);
$memory = parse_shorthand_int(ini_get("memory_limit"));
// changing of memory limit is disabled / failed
if($memory == -1) {
$memory = $default_limit;
}
return $memory;
}
private function get_thumb($tmpname) { private function get_thumb($tmpname) {
global $config; global $config;
@ -116,7 +94,7 @@ class RegenThumb extends Extension {
$max_height = $config->get_int('thumb_height'); $max_height = $config->get_int('thumb_height');
$memory_use = (filesize($tmpname)*2) + ($width*$height*4) + (4*1024*1024); $memory_use = (filesize($tmpname)*2) + ($width*$height*4) + (4*1024*1024);
$memory_limit = $this->get_memory_limit(); $memory_limit = get_memory_limit();
if($memory_use > $memory_limit) { if($memory_use > $memory_limit) {
$thumb = imagecreatetruecolor($max_width, min($max_height, 64)); $thumb = imagecreatetruecolor($max_width, min($max_height, 64));