Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GD2 Adapter PHP memory_limit #481

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions lib/Magento/Image/Adapter/Gd2.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,14 @@ public function open($filename)
*/
protected function _isMemoryLimitReached()
{
$limit = $this->_convertToByte(ini_get('memory_limit'));
$requiredMemory = $this->_getImageNeedMemorySize($this->_fileName);
return (memory_get_usage(true) + $requiredMemory) > $limit;
$memory_limit = ini_get('memory_limit');
if ($memory_limit == -1) {
return false;
} else {
$limit = $this->_convertToByte($memory_limit);
$requiredMemory = $this->_getImageNeedMemorySize($this->_fileName);
return (memory_get_usage(true) + $requiredMemory) > $limit;
}
}

/**
Expand Down Expand Up @@ -112,7 +117,7 @@ protected function _getImageNeedMemorySize($file)
}

/**
* Converts memory value (e.g. 64M, 129KB) to bytes.
* Converts memory value (e.g. 64M, 129K) to bytes.
* Case insensitive value might be used.
*
* @param string $memoryValue
Expand All @@ -124,7 +129,7 @@ protected function _convertToByte($memoryValue)
return (int)$memoryValue * pow(1024, 3);
} elseif (stripos($memoryValue, 'M') !== false) {
return (int)$memoryValue * 1024 * 1024;
} elseif (stripos($memoryValue, 'KB') !== false) {
} elseif (stripos($memoryValue, 'K') !== false) {
return (int)$memoryValue * 1024;
}

Expand Down