diff --git a/README.txt b/README.txt index 622d90a9..b419b692 100644 --- a/README.txt +++ b/README.txt @@ -1,10 +1,13 @@ - _________.__ .__ .__ ________ - / _____/| |__ |__| _____ _____ |__| ____ \_____ \ - \_____ \ | | \| |/ \ / \| |/ __ \ / ____/ - / \| Y \ | Y Y \ Y Y \ \ ___// \ - /_______ /|___| /__|__|_| /__|_| /__|\___ >_______ \ - \/ \/ \/ \/ \/ \/ + _________.__ .__ .__ ________ + / _____/| |__ |__| _____ _____ |__| ____ \_____ \ + \_____ \ | | \ | | / \ / \ | |_/ __ \ / ____/ + / \| Y \| || Y Y \| Y Y \| |\ ___/ / \ + /_______ /|___| /|__||__|_| /|__|_| /|__| \___ >\_______ \ + \/ \/ \/ \/ \/ \/ + +_________________________________________________________________________ + Shimmie Alpha ~~~~~~~~~~~~~ @@ -58,6 +61,15 @@ database and file formats haven't changed *completely*, it's different enough to be a pain. +Custom Configuration +~~~~~~~~~~~~~~~~~~~~ + +Various aspects of Shimmie can be configured to suit your site specific +needs via the file "config.php" (created after installation). +Take a look at "core/default_config.inc.php" for the available options +that can used. + + Development Info ~~~~~~~~~~~~~~~~ http://shimmie.shishnet.org/doc/ @@ -70,7 +82,7 @@ Contact ~~~~~~~ #shimmie on Freenode -- IRC webmaster at shishnet.org -- email -https://github.com/shish/shimmie2 -- bug tracker +https://github.com/shish/shimmie2/issues -- bug tracker Licence diff --git a/contrib/resize/main.php b/contrib/resize/main.php index 51b1bf24..bb5b423b 100644 --- a/contrib/resize/main.php +++ b/contrib/resize/main.php @@ -172,8 +172,19 @@ class ResizeImage extends Extension { throw new ImageResizeException("The image size does not match what is in the database! - Aborting Resize."); } - /* Check memory usage limits */ - $memory_use = (filesize($image_filename)*2) + ($width*$height*4) + (4*1024*1024); + /* + Check Memory usage limits + + Old check: $memory_use = (filesize($image_filename)*2) + ($width*$height*4) + (4*1024*1024); + New check: memory_use = width * height * (bits per channel) * channels * 2.5 + + It didn't make sense to compute the memory usage based on the NEW size for the image. ($width*$height*4) + We need to consider the size that we are GOING TO instead. + + The factor of 2.5 is simply a rough guideline. + http://stackoverflow.com/questions/527532/reasonable-php-memory-limit-for-image-resize + */ + $memory_use = ($info[0] * $info[1] * ($info['bits'] / 8) * $info['channels'] * 2.5) / 1024; $memory_limit = get_memory_limit(); if ($memory_use > $memory_limit) { @@ -191,7 +202,7 @@ class ResizeImage extends Extension { else $factor = min( $width / $image_obj->width, $height / $image_obj->height ); $new_width = round( $image_obj->width * $factor ); - $new_height = round( $image_obj->height * $factor ); + $new_height = round( $image_obj->height * $factor ); } /* Attempt to load the image */ diff --git a/core/default_config.inc.php b/core/default_config.inc.php index 2f3003ca..c6a44b57 100644 --- a/core/default_config.inc.php +++ b/core/default_config.inc.php @@ -1,4 +1,16 @@ diff --git a/core/util.inc.php b/core/util.inc.php index 04fb2b65..158d1f2e 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -547,24 +547,48 @@ function get_memory_limit() { global $config; // thumbnail generation requires lots of memory - $default_limit = 8*1024*1024; + $default_limit = 8*1024*1024; // 8 MB of memory is PHP's default. $shimmie_limit = parse_shorthand_int($config->get_int("thumb_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); + + /* + Get PHP's configured memory limit. + Note that this is set to -1 for NO memory limit. + + http://ca2.php.net/manual/en/ini.core.php#ini.memory-limit + */ $memory = parse_shorthand_int(ini_get("memory_limit")); - - // changing of memory limit is disabled / failed - if($memory == -1) { - $memory = $default_limit; + + if ($memory == -1) { + // No memory limit. + + // Return the larger of the set limits. + if ($shimmie_limit > $default_limit) { + return $shimmie_limit; + } else { + return $default_limit; // return the default memory limit + } + } else { + // PHP has a memory limit set. + + if ($shimmie_limit > $memory) { + // Shimmie wants more memory than what PHP is currently set for. + + // Attempt to set PHP's memory limit. + if ( ini_set("memory_limit", $shimmie_limit) === FALSE ) { + /* We can't change PHP's limit, oh well, return whatever its currently set to */ + return $memory; + } + $memory = parse_shorthand_int(ini_get("memory_limit")); + } + + // PHP's memory limit is more than Shimmie needs. + return $memory; // return the current setting } - - assert($memory > 0); - - return $memory; } /**