예제 #1
0
 /**
  * Mutator method for the uploadedFile property.
  * Accepts the following inputs:
  * - An absolute string url (for fetching remote files).
  * - An array (data parsed from the $_FILES array),
  * - A Symfony uploaded file object.
  *
  * @param mixed $uploadedFile
  */
 public function setUploadedFile($uploadedFile)
 {
     if (!$this->keep_old_files) {
         $this->clear();
     }
     if ($uploadedFile == STAPLER_NULL) {
         $this->clearAttributes();
         return;
     }
     $this->uploadedFile = FileFactory::create($uploadedFile);
     $this->instanceWrite('file_name', $this->uploadedFile->getFilename());
     $this->instanceWrite('file_size', $this->uploadedFile->getSize());
     $this->instanceWrite('content_type', $this->uploadedFile->getMimeType());
     $this->instanceWrite('updated_at', date('Y-m-d H:i:s'));
     $this->queueAllForWrite();
 }
예제 #2
0
 /**
  * Resize an image using the computed settings.
  *
  * @param  FileInterface $file
  * @param  Style $style
  * @return string
  */
 public function resize(FileInterface $file, Style $style)
 {
     $filePath = tempnam(sys_get_temp_dir(), 'STP') . '.' . $file->getFilename();
     list($width, $height, $option) = $this->parseStyleDimensions($style);
     $method = "resize" . ucfirst($option);
     if ($method == 'resizeCustom') {
         $this->resizeCustom($file, $style->dimensions)->save($filePath, $style->convertOptions);
         return $filePath;
     }
     $image = $this->imagine->open($file->getRealPath());
     if ($style->autoOrient) {
         $image = $this->autoOrient($file->getRealPath(), $image);
     }
     $this->{$method}($image, $width, $height)->save($filePath, $style->convertOptions);
     return $filePath;
 }