/**
  * Creates and saves a thumbnail picture.
  */
 public function createThumbnail($thumbnailWidth = ATTACHMENT_THUMBNAIL_WIDTH, $thumbnailHeight = ATTACHMENT_THUMBNAIL_HEIGHT, $addSourceInfo = ATTACHMENT_THUMBNAIL_ADD_SOURCE_INFO, $useEmbedded = ATTACHMENT_THUMBNAIL_USE_EMBEDDED)
 {
     // make thumbnail
     $sourceFile = WCF_DIR . 'attachments/attachment-' . $this->attachmentID;
     $targetFile = WCF_DIR . 'attachments/thumbnail-' . $this->attachmentID;
     $thumbnail = new Thumbnail($sourceFile, $thumbnailWidth, $thumbnailHeight, $addSourceInfo, $this->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
             $thumbnailSize = intval(filesize($targetFile));
             list($thumbnailWidth, $thumbnailHeight, ) = @getImagesize($targetFile);
             $sql = "UPDATE\twcf" . WCF_N . "_attachment\n\t\t\t\t\tSET \tthumbnailType = '" . escapeString($thumbnail->getMimeType()) . "',\n\t\t\t\t\t\tthumbnailSize = " . $thumbnailSize . ",\n\t\t\t\t\t\tthumbnailWidth = " . $thumbnailWidth . ",\n\t\t\t\t\t\tthumbnailHeight = " . $thumbnailHeight . "\n\t\t\t\t\tWHERE \tattachmentID = " . $this->attachmentID;
             WCF::getDB()->registerShutdownUpdate($sql);
             // update data
             $this->data['thumbnailType'] = $thumbnail->getMimeType();
             $this->data['thumbnailSize'] = $thumbnailSize;
         }
     } catch (Exception $e) {
     }
 }
 /**
  * Scales the style preview image.
  * 
  * @param	string		$filename
  * @return	boolean
  */
 public static function scalePreviewImage($filename)
 {
     require_once WCF_DIR . 'lib/data/image/Thumbnail.class.php';
     $thumbnail = new Thumbnail($filename, self::STYLE_PREVIEW_IMAGE_MAX_WIDTH, self::STYLE_PREVIEW_IMAGE_MAX_HEIGHT);
     if ($source = $thumbnail->makeThumbnail()) {
         require_once WCF_DIR . 'lib/system/io/File.class.php';
         $file = new File($filename);
         $file->write($source);
         $file->close();
         return true;
     }
     return false;
 }
 /**
  * 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;
 }