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


PHP Thumbnail::open方法代码示例

本文整理汇总了PHP中Thumbnail::open方法的典型用法代码示例。如果您正苦于以下问题:PHP Thumbnail::open方法的具体用法?PHP Thumbnail::open怎么用?PHP Thumbnail::open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Thumbnail的用法示例。


在下文中一共展示了Thumbnail::open方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getAvatar

 public static function getAvatar(\User $user, $res)
 {
     global $wgDefaultAvatar, $wgDefaultAvatarRes;
     $path = $wgDefaultAvatar;
     // If user exists
     if ($user && $user->getId()) {
         global $wgUploadDirectory, $wgUploadPath;
         $avatarPath = "/avatars/{$user->getId()}/{$res}.png";
         // Check if requested avatar thumbnail exists
         if (file_exists($wgUploadDirectory . $avatarPath)) {
             $path = $wgUploadPath . $avatarPath;
         } else {
             if ($res !== 'original') {
                 // Dynamically generate upon request
                 $originalAvatarPath = "/avatars/{$user->getId()}/original.png";
                 if (file_exists($wgUploadDirectory . $originalAvatarPath)) {
                     $image = Thumbnail::open($wgUploadDirectory . $originalAvatarPath);
                     $image->createThumbnail($res, $wgUploadDirectory . $avatarPath);
                     $image->cleanup();
                     $path = $wgUploadPath . $avatarPath;
                 }
             }
         }
     }
     return $path;
 }
开发者ID:zoglun,项目名称:MW-Avatar,代码行数:26,代码来源:Avatar_body.php

示例2: processUpload

 private function processUpload()
 {
     $request = $this->getRequest();
     $dataurl = $request->getVal('avatar');
     if (!$dataurl || parse_url($dataurl, PHP_URL_SCHEME) !== 'data') {
         $this->displayMessage($this->msg('avatar-notuploaded'));
         return false;
     }
     $img = Thumbnail::open($dataurl);
     global $wgMaxAvatarResolution;
     switch ($img->type) {
         case IMAGETYPE_GIF:
         case IMAGETYPE_PNG:
         case IMAGETYPE_JPEG:
             break;
         default:
             $this->displayMessage($this->msg('avatar-invalid'));
             return false;
     }
     // Must be square
     if ($img->width !== $img->height) {
         $this->displayMessage($this->msg('avatar-notsquare'));
         return false;
     }
     // Check if image is too small
     if ($img->width < 32 || $img->height < 32) {
         $this->displayMessage($this->msg('avatar-toosmall'));
         return false;
     }
     // Check if image is too big
     if ($img->width > $wgMaxAvatarResolution || $img->height > $wgMaxAvatarResolution) {
         $this->displayMessage($this->msg('avatar-toolarge'));
         return false;
     }
     $user = $this->getUser();
     Avatars::deleteAvatar($user);
     // Avatar directories
     global $wgAvatarUploadDirectory;
     $uploadDir = $wgAvatarUploadDirectory . '/' . $this->getUser()->getId() . '/';
     @mkdir($uploadDir, 0777, true);
     // We do this to convert format to png
     $img->createThumbnail($wgMaxAvatarResolution, $uploadDir . 'original.png');
     // We only create thumbnail with default resolution here. Others are generated on demand
     global $wgDefaultAvatarRes;
     $img->createThumbnail($wgDefaultAvatarRes, $uploadDir . $wgDefaultAvatarRes . '.png');
     $img->cleanup();
     $this->displayMessage($this->msg('avatar-saved'));
     global $wgAvatarLogInRC;
     $logEntry = new \ManualLogEntry('avatar', 'upload');
     $logEntry->setPerformer($this->getUser());
     $logEntry->setTarget($this->getUser()->getUserPage());
     $logId = $logEntry->insert();
     $logEntry->publish($logId, $wgAvatarLogInRC ? 'rcandudp' : 'udp');
     return true;
 }
开发者ID:nbdd0121,项目名称:MW-Avatar,代码行数:55,代码来源:SpecialUpload.php


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