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


PHP Thumbnail::getMimeType方法代码示例

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


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

示例1: saveThumbnail

 /**
  * Creates and saves a thumbnail picture
  * 
  * @param	array		$attachment
  */
 public static function saveThumbnail(&$attachment, $thumbnailWidth = ATTACHMENT_THUMBNAIL_WIDTH, $thumbnailHeight = ATTACHMENT_THUMBNAIL_HEIGHT, $addSourceInfo = ATTACHMENT_THUMBNAIL_ADD_SOURCE_INFO, $useEmbedded = ATTACHMENT_THUMBNAIL_USE_EMBEDDED)
 {
     // make thumbnail
     $targetFile = WCF_DIR . 'attachments/thumbnail-' . $attachment['attachmentID'];
     $thumbnail = new Thumbnail($attachment['attachment'], $thumbnailWidth, $thumbnailHeight, $addSourceInfo, $attachment['attachmentName'], $useEmbedded);
     // get thumbnail
     try {
         if ($thumbnailData = $thumbnail->makeThumbnail()) {
             // save thumbnail
             $file = new File($targetFile);
             $file->write($thumbnailData);
             unset($thumbnailData);
             $file->close();
             // update database entry
             $sql = "UPDATE\twcf" . WCF_N . "_attachment\n\t\t\t\t\tSET \tthumbnailType = '" . escapeString($thumbnail->getMimeType()) . "',\n\t\t\t\t\t\tthumbnailSize = " . intval(filesize($targetFile)) . "\n\t\t\t\t\tWHERE \tattachmentID = " . $attachment['attachmentID'];
             WCF::getDB()->registerShutdownUpdate($sql);
         }
     } catch (Exception $e) {
     }
 }
开发者ID:joaocustodio,项目名称:EmuDevstore-1,代码行数:25,代码来源:AttachmentsEditor.class.php

示例2: create

 /**
  * Creates a new avatar.
  * 
  * @param	string		$tmpName
  * @param	string		$name
  * @param	string		$field
  * @return	integer		avatar id
  */
 public static function create($tmpName, $name, $field, $userID = 0, $groupID = 0, $neededPoints = 0, $avatarCategoryID = 0)
 {
     // check avatar content
     if (!ImageUtil::checkImageContent($tmpName)) {
         throw new UserInputException($field, 'badAvatar');
     }
     // get file extension
     /*$fileExtension = '';
     		if (!empty($name) && StringUtil::indexOf($name, '.') !== false) {
     			$fileExtension = StringUtil::toLowerCase(StringUtil::substring($name, StringUtil::lastIndexOf($name, '.') + 1));
     		}*/
     // get image data
     if (($imageData = @getImageSize($tmpName)) === false) {
         throw new UserInputException($field, 'badAvatar');
     }
     // get file extension by mime
     $fileExtension = ImageUtil::getExtensionByMimeType($imageData['mime']);
     // check file extension
     if (!in_array($fileExtension, self::getAllowedFileExtensions())) {
         throw new UserInputException($field, 'notAllowedExtension');
     }
     // get avatar size
     $width = $imageData[0];
     $height = $imageData[1];
     if (!$width || !$height) {
         throw new UserInputException($field, 'badAvatar');
     }
     $size = @filesize($tmpName);
     // generate thumbnail if necessary
     if ($width > WCF::getUser()->getPermission('user.profile.avatar.maxWidth') || $height > WCF::getUser()->getPermission('user.profile.avatar.maxHeight')) {
         $thumbnail = new Thumbnail($tmpName, WCF::getUser()->getPermission('user.profile.avatar.maxWidth'), WCF::getUser()->getPermission('user.profile.avatar.maxHeight'));
         $thumbnailSrc = $thumbnail->makeThumbnail();
         if ($thumbnailSrc) {
             $file = new File($tmpName);
             $file->write($thumbnailSrc);
             $file->close();
             // refresh avatar size
             list($width, $height, ) = @getImageSize($tmpName);
             clearstatcache();
             $size = @filesize($tmpName);
             // get new file extension
             $fileExtension = ImageUtil::getExtensionByMimeType($thumbnail->getMimeType());
         }
         unset($thumbnail, $thumbnailSrc);
     }
     // check size again
     if ($width > WCF::getUser()->getPermission('user.profile.avatar.maxWidth') || $height > WCF::getUser()->getPermission('user.profile.avatar.maxHeight') || $size > WCF::getUser()->getPermission('user.profile.avatar.maxSize')) {
         throw new UserInputException($field, 'tooLarge');
     }
     // create avatar
     $avatarID = self::insert(basename($name), array('avatarExtension' => $fileExtension, 'width' => $width, 'height' => $height, 'userID' => $userID, 'groupID' => $groupID, 'neededPoints' => $neededPoints, 'avatarCategoryID' => $avatarCategoryID));
     // copy avatar to avatar folder
     if (!@copy($tmpName, WCF_DIR . 'images/avatars/avatar-' . $avatarID . '.' . $fileExtension)) {
         // copy failed
         // delete avatar
         @unlink($tmpName);
         $sql = "DELETE FROM\twcf" . WCF_N . "_avatar\n\t\t\t\tWHERE\t\tavatarID = " . $avatarID;
         WCF::getDB()->sendQuery($sql);
         throw new UserInputException($field, 'copyFailed');
     }
     // set permissions
     @chmod(WCF_DIR . 'images/avatars/avatar-' . $avatarID . '.' . $fileExtension, 0666);
     return $avatarID;
 }
开发者ID:joaocustodio,项目名称:EmuDevstore-1,代码行数:72,代码来源:AvatarEditor.class.php


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