Beispiel #1
0
 /**
  * Build a \Torann\MediaSort\File\UploadedFile object from
  * a Symfony\Component\HttpFoundation\File\UploadedFile object.
  *
  * @param \Symfony\Component\HttpFoundation\File\UploadedFile $file
  *
  * @return \Torann\MediaSort\File\UploadedFile
  * @throws \Torann\MediaSort\Exceptions\FileException
  */
 protected function createFromObject(SymfonyUploadedFile $file)
 {
     $path = $file->getPathname();
     $originalName = $file->getClientOriginalName();
     $mimeType = $file->getClientMimeType();
     $size = $file->getClientSize();
     $error = $file->getError();
     $uploadFile = new UploadedFile($path, $originalName, $mimeType, $size, $error);
     if (!$uploadFile->isValid()) {
         throw new FileException($uploadFile->getErrorMessage($uploadFile->getError()));
     }
     return $uploadFile;
 }
Beispiel #2
0
 /**
  * Process the queuedForWrite que.
  *
  * @return void
  */
 protected function flushWrites()
 {
     foreach ($this->queuedForWrite as $style) {
         if ($style->value && $this->uploadedFile->isImage()) {
             $file = $this->resizer->resize($this->uploadedFile, $style);
         } else {
             $file = $this->uploadedFile->getRealPath();
         }
         // Only move it real
         if ($filePath = $this->path($style->name)) {
             $this->move($file, $filePath);
         }
     }
     $this->queuedForWrite = [];
 }
Beispiel #3
0
 /**
  * Resize an image to an exact width and height.
  *
  * @param UploadedFile $file
  * @param string       $width  - The image's new width.
  * @param string       $height - The image's new height.
  *
  * @return \stdClass
  */
 protected function resizeExact(UploadedFile $file, $width, $height)
 {
     return $this->imagine->open($file->getRealPath())->resize(new Box($width, $height));
 }