本文整理汇总了PHP中wcf\util\FileUtil::getMemoryLimit方法的典型用法代码示例。如果您正苦于以下问题:PHP FileUtil::getMemoryLimit方法的具体用法?PHP FileUtil::getMemoryLimit怎么用?PHP FileUtil::getMemoryLimit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wcf\util\FileUtil
的用法示例。
在下文中一共展示了FileUtil::getMemoryLimit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generateThumbnails
/**
* Generates thumbnails.
*/
public function generateThumbnails()
{
if (empty($this->objects)) {
$this->readObjects();
}
foreach ($this->objects as $attachment) {
if (!$attachment->isImage) {
// create thumbnails for every file that isn't an image
$this->eventAttachment = $attachment;
$this->eventData = array();
EventHandler::getInstance()->fireAction($this, 'generateThumbnail');
if (!empty($this->eventData)) {
$attachment->update($this->eventData);
}
continue;
}
if ($attachment->width <= 144 && $attachment->height < 144) {
continue;
// image smaller than thumbnail size; skip
}
$adapter = ImageHandler::getInstance()->getAdapter();
// check memory limit
$neededMemory = $attachment->width * $attachment->height * ($attachment->fileType == 'image/png' ? 4 : 3) * 2.1;
if (FileUtil::getMemoryLimit() != -1 && FileUtil::getMemoryLimit() < memory_get_usage() + $neededMemory) {
continue;
}
$adapter->loadFile($attachment->getLocation());
$updateData = array();
// remove / reset old thumbnails
if ($attachment->tinyThumbnailType) {
@unlink($attachment->getTinyThumbnailLocation());
$updateData['tinyThumbnailType'] = '';
$updateData['tinyThumbnailSize'] = 0;
$updateData['tinyThumbnailWidth'] = 0;
$updateData['tinyThumbnailHeight'] = 0;
}
if ($attachment->thumbnailType) {
@unlink($attachment->getThumbnailLocation());
$updateData['thumbnailType'] = '';
$updateData['thumbnailSize'] = 0;
$updateData['thumbnailWidth'] = 0;
$updateData['thumbnailHeight'] = 0;
}
// create tiny thumbnail
$tinyThumbnailLocation = $attachment->getTinyThumbnailLocation();
$thumbnail = $adapter->createThumbnail(144, 144, false);
$adapter->writeImage($thumbnail, $tinyThumbnailLocation);
if (file_exists($tinyThumbnailLocation) && ($imageData = @getImageSize($tinyThumbnailLocation)) !== false) {
$updateData['tinyThumbnailType'] = $imageData['mime'];
$updateData['tinyThumbnailSize'] = @filesize($tinyThumbnailLocation);
$updateData['tinyThumbnailWidth'] = $imageData[0];
$updateData['tinyThumbnailHeight'] = $imageData[1];
}
// create standard thumbnail
if ($attachment->width > ATTACHMENT_THUMBNAIL_WIDTH || $attachment->height > ATTACHMENT_THUMBNAIL_HEIGHT) {
$thumbnailLocation = $attachment->getThumbnailLocation();
$thumbnail = $adapter->createThumbnail(ATTACHMENT_THUMBNAIL_WIDTH, ATTACHMENT_THUMBNAIL_HEIGHT, ATTACHMENT_RETAIN_DIMENSIONS);
$adapter->writeImage($thumbnail, $thumbnailLocation);
if (file_exists($thumbnailLocation) && ($imageData = @getImageSize($thumbnailLocation)) !== false) {
$updateData['thumbnailType'] = $imageData['mime'];
$updateData['thumbnailSize'] = @filesize($thumbnailLocation);
$updateData['thumbnailWidth'] = $imageData[0];
$updateData['thumbnailHeight'] = $imageData[1];
}
}
if (!empty($updateData)) {
$attachment->update($updateData);
}
}
}