mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-02 01:52:10 +09:00
#18402013 : added estimation function called before loading image to create thumbnail (fixed a crash occurred when creating a thumbnail of large image file)
git-svn-id: http://xe-core.googlecode.com/svn/sandbox@6899 201d5d3c-b55e-5fd7-737f-ddc643e51545
This commit is contained in:
parent
fd50fdd9e3
commit
8cd154be31
1 changed files with 38 additions and 1 deletions
|
|
@ -397,6 +397,40 @@
|
|||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief convert size in string into numeric value
|
||||
* @param[in] $val size in string (ex., 10, 10K, 10M, 10G )
|
||||
* @return converted size
|
||||
*/
|
||||
function returnBytes($val)
|
||||
{
|
||||
$val = trim($val);
|
||||
$last = strtolower(substr($val, -1));
|
||||
if($last == 'g') $val *= 1024*1024*1024;
|
||||
else if($last == 'm') $val *= 1024*1024;
|
||||
else if($last == 'k') $val *= 1024;
|
||||
|
||||
return $val;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief check available memory to load image file
|
||||
* @param[in] $imageInfo image info retrieved by getimagesize function
|
||||
* @return true: it's ok, false: otherwise
|
||||
*/
|
||||
function checkMemoryLoadImage(&$imageInfo)
|
||||
{
|
||||
if(!function_exists('memory_get_usage')) return true;
|
||||
$K64 = 65536;
|
||||
$TWEAKFACTOR = 1.5;
|
||||
$channels = $imageInfo['channels'];
|
||||
if(!$channels) $channels = 6; //for png
|
||||
$memoryNeeded = round( ($imageInfo[0] * $imageInfo[1] * $imageInfo['bits'] * $channels / 8 + $K64 ) * $TWEAKFACTOR );
|
||||
$availableMemory = FileHandler::returnBytes(ini_get('memory_limit')) - memory_get_usage();
|
||||
if($availableMemory < $memoryNeeded) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief moves an image file (resizing is possible)
|
||||
* @param[in] $source_file path of the source file
|
||||
|
|
@ -416,7 +450,10 @@
|
|||
if(!$resize_height) $resize_height = $resize_width;
|
||||
|
||||
// retrieve source image's information
|
||||
list($width, $height, $type, $attrs) = @getimagesize($source_file);
|
||||
$imageInfo = getimagesize($source_file);
|
||||
if(!FileHandler::checkMemoryLoadImage($imageInfo)) return false;
|
||||
list($width, $height, $type, $attrs) = $imageInfo;
|
||||
|
||||
if($width<1 || $height<1) return;
|
||||
|
||||
switch($type) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue