* Generates thumbnails.
*/
public function generateThumbnails() {
- if (!empty($this->objects)) {
+ if (empty($this->objects)) {
$this->readObjects();
}
continue; // image smaller than thumbnail size; skip
}
+
$adapter = ImageHandler::getInstance()->getAdapter();
+
+ // check memory limit
+ $neededMemory = $attachment->width * $attachment->height * ($attachment->imageType == 'image/png' ? 4 : 3) * 2.1;
+ if (FileUtil::getMemoryLimit() != -1 && FileUtil::getMemoryLimit() < (memory_get_usage() + $neededMemory)) {
+ continue;
+ }
+
$adapter->loadFile($attachment->getLocation());
$updateData = array();
*/
protected static $finfo = null;
+ /**
+ * memory limit in bytes
+ * @var integer
+ */
+ protected static $memoryLimit = null;
+
/**
* chmod mode
* @var string
}
}
+ /**
+ * Returns memory limit in bytes.
+ *
+ * @return integer
+ */
+ public static function getMemoryLimit() {
+ if (self::$memoryLimit === null) {
+ self::$memoryLimit = 0;
+
+ $memoryLimit = ini_get('memory_limit');
+
+ // no limit
+ if ($memoryLimit == -1) {
+ self::$memoryLimit = -1;
+ }
+
+ // completely numeric, PHP assumes byte
+ if (is_numeric($memoryLimit)) {
+ self::$memoryLimit = $memoryLimit;
+ }
+
+ // PHP supports 'K', 'M' and 'G' shorthand notation
+ if (preg_match('~^(\d+)([KMG])$~', $memoryLimit, $matches)) {
+ switch ($matches[2]) {
+ case 'K':
+ self::$memoryLimit = $matches[1] * 1024;
+ break;
+
+ case 'M':
+ self::$memoryLimit = $matches[1] * 1024 * 1024;
+ break;
+
+ case 'G':
+ self::$memoryLimit = $matches[1] * 1024 * 1024 * 1024;
+ break;
+ }
+ }
+ }
+
+ return self::$memoryLimit;
+ }
+
private function __construct() { }
}