当前位置: 首页>>代码示例>>PHP>>正文


PHP FileUtil::getMemoryLimit方法代码示例

本文整理汇总了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);
         }
     }
 }
开发者ID:nick-strohm,项目名称:WCF,代码行数:73,代码来源:AttachmentAction.class.php


注:本文中的wcf\util\FileUtil::getMemoryLimit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。