コード例 #1
0
ファイル: StyleAction.class.php プロジェクト: jacboy/WCF
 /**
  * Handles uploaded preview images.
  * 
  * @return	array<string>
  */
 public function upload()
 {
     // save files
     $files = $this->parameters['__files']->getFiles();
     $file = $files[0];
     try {
         if (!$file->getValidationErrorType()) {
             // shrink preview image if necessary
             $fileLocation = $file->getLocation();
             $imageData = getimagesize($fileLocation);
             if ($imageData[0] > Style::PREVIEW_IMAGE_MAX_WIDTH || $imageData[1] > Style::PREVIEW_IMAGE_MAX_HEIGHT) {
                 try {
                     $adapter = ImageHandler::getInstance()->getAdapter();
                     $adapter->loadFile($fileLocation);
                     $fileLocation = FileUtil::getTemporaryFilename();
                     $thumbnail = $adapter->createThumbnail(Style::PREVIEW_IMAGE_MAX_WIDTH, Style::PREVIEW_IMAGE_MAX_HEIGHT, false);
                     $adapter->writeImage($thumbnail, $fileLocation);
                     $imageData = getimagesize($fileLocation);
                 } catch (SystemException $e) {
                     throw new UserInputException('image');
                 }
             }
             // move uploaded file
             if (@copy($fileLocation, WCF_DIR . 'images/stylePreview-' . $this->parameters['tmpHash'] . '.' . $file->getFileExtension())) {
                 @unlink($fileLocation);
                 // store extension within session variables
                 WCF::getSession()->register('stylePreview-' . $this->parameters['tmpHash'], $file->getFileExtension());
                 if ($this->parameters['styleID']) {
                     $this->updateStylePreviewImage($this->style);
                     return array('url' => WCF::getPath() . 'images/stylePreview-' . $this->parameters['styleID'] . '.' . $file->getFileExtension());
                 }
                 // return result
                 return array('url' => WCF::getPath() . 'images/stylePreview-' . $this->parameters['tmpHash'] . '.' . $file->getFileExtension());
             } else {
                 throw new UserInputException('image', 'uploadFailed');
             }
         }
     } catch (UserInputException $e) {
         $file->setValidationErrorType($e->getType());
     }
     return array('errorType' => $file->getValidationErrorType());
 }
コード例 #2
0
 /**
  * Craps an avatar.
  */
 public function cropAvatar()
 {
     // created clipped avatar as base for new thumbnails
     $adapter = ImageHandler::getInstance()->getAdapter();
     $adapter->loadFile($this->avatar->getLocation());
     $adapter->clip($this->parameters['cropX'], $this->parameters['cropY'], UserAvatar::$maxThumbnailSize, UserAvatar::$maxThumbnailSize);
     // update thumbnails
     foreach (UserAvatar::$avatarThumbnailSizes as $size) {
         $thumbnail = $adapter->createThumbnail($size, $size);
         $adapter->writeImage($thumbnail, $this->avatar->getLocation($size));
     }
     // update database entry
     $this->avatar->update(array('cropX' => $this->parameters['cropX'], 'cropY' => $this->parameters['cropY']));
     return array('url' => $this->avatar->getURL(96));
 }
コード例 #3
0
ファイル: StyleEditor.class.php プロジェクト: nick-strohm/WCF
 /**
  * Scales the style preview image.
  * 
  * @param	string		$filename
  */
 public static function scalePreviewImage($filename)
 {
     $adapter = ImageHandler::getInstance()->getAdapter();
     $adapter->loadFile(WCF_DIR . 'images/' . $filename);
     $thumbnail = $adapter->createThumbnail(Style::PREVIEW_IMAGE_MAX_WIDTH, Style::PREVIEW_IMAGE_MAX_HEIGHT);
     $adapter->writeImage($thumbnail, WCF_DIR . 'images/' . $filename);
 }
コード例 #4
0
 /**
  * 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);
         }
     }
 }