From b1b2edf021dcb98ea47b37581e75dca4a4c5201d Mon Sep 17 00:00:00 2001 From: shish Date: Tue, 24 Apr 2007 19:12:05 +0000 Subject: [PATCH] only one copy of get_memory_limit... git-svn-id: file:///home/shish/svn/shimmie2/trunk@9 7f39781d-f577-437e-ae19-be835c7a54ca --- core/ext/image.ext.php | 24 +----------------------- core/util.inc.php | 23 +++++++++++++++++++++++ ext/regen_thumb.ext.php | 24 +----------------------- 3 files changed, 25 insertions(+), 46 deletions(-) diff --git a/core/ext/image.ext.php b/core/ext/image.ext.php index 172f630e..fc37a8fe 100644 --- a/core/ext/image.ext.php +++ b/core/ext/image.ext.php @@ -106,28 +106,6 @@ class ImageIO extends Extension { 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) { global $config; @@ -139,7 +117,7 @@ class ImageIO extends Extension { $max_height = $config->get_int('thumb_height'); $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) { $thumb = imagecreatetruecolor($max_width, min($max_height, 64)); diff --git a/core/util.inc.php b/core/util.inc.php index f1cf1b64..2dffdd60 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -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) { $text = trim($text); $text = html_escape($text); diff --git a/ext/regen_thumb.ext.php b/ext/regen_thumb.ext.php index 13ca330b..8a5ebc7d 100644 --- a/ext/regen_thumb.ext.php +++ b/ext/regen_thumb.ext.php @@ -83,28 +83,6 @@ class RegenThumb extends Extension { 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) { global $config; @@ -116,7 +94,7 @@ class RegenThumb extends Extension { $max_height = $config->get_int('thumb_height'); $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) { $thumb = imagecreatetruecolor($max_width, min($max_height, 64));