From 13c08e2f99078e29611f641340c2ef78eaf6f560 Mon Sep 17 00:00:00 2001 From: Michael Klier Date: Sun, 26 Oct 2008 14:58:33 +0100 Subject: moved crop/resize functions out of fetch.php for reusability darcs-hash:20081026135833-23886-a9c8e910571c6e7a4e1603a2ebd365b3ed37108a.gz --- inc/common.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'inc/common.php') diff --git a/inc/common.php b/inc/common.php index 9b284617b..faee93623 100644 --- a/inc/common.php +++ b/inc/common.php @@ -1424,4 +1424,34 @@ function license_img($type){ return ''; } +/** + * Checks if the given amount of memory is available + * + * If the memory_get_usage() function is not available the + * function just assumes $bytes of already allocated memory + * + * @param int $mem Size of memory you want to allocate in bytes + * @param int $used already allocated memory (see above) + * @author Filip Oscadal + * @author Andreas Gohr + */ +function is_mem_available($mem,$bytes=1048576){ + $limit = trim(ini_get('memory_limit')); + if(empty($limit)) return true; // no limit set! + + // parse limit to bytes + $limit = php_to_byte($limit); + + // get used memory if possible + if(function_exists('memory_get_usage')){ + $used = memory_get_usage(); + } + + if($used+$mem > $limit){ + return false; + } + + return true; +} + //Setup VIM: ex: et ts=2 enc=utf-8 : -- cgit v1.2.3