Beispiel #1
0
 public function tempOriginal(Image $image)
 {
     // Recreate original filename
     $tempOriginalPath = tempnam(sys_get_temp_dir(), null);
     $originalPath = sprintf('%s-%s.%s', $image->getKey(), $this->generateHash($image), Mime::getExtensionForMimeType($image->mime_type));
     // Download file
     $this->ftp->fget($tempOriginalPath, $originalPath, FtpClient::ASCII);
     return new File($tempOriginalPath);
 }
Beispiel #2
0
 /**
  * Saves a new image from a file found on the server's filesystem.
  *
  * @param File $file
  * @param \TippingCanoe\Imager\Model\Imageable|\Illuminate\Database\Eloquent\Model $imageable
  * @param array $attributes
  * @throws Exception
  * @return null
  */
 public function saveFromFile(File $file, Imageable $imageable = null, array $attributes = [])
 {
     if (!array_key_exists($file->getMimeType(), Mime::getTypes())) {
         throw new Exception(sprintf('File type %s not supported', $file->getMimeType()));
     }
     $image = $this->createImageRecord($file, $attributes);
     // Believe it or not, imageables are optional!
     if ($imageable) {
         $imageable->images()->save($image);
     }
     $this->saveFile($file, $image);
     return $image;
 }
Beispiel #3
0
 /**
  * Tells the driver to prepare a copy of the original image locally.
  *
  * @param Image $image
  * @return File
  */
 public function tempOriginal(Image $image)
 {
     // Recreate original filename
     $tempOriginalPath = tempnam(sys_get_temp_dir(), null);
     $originalPath = sprintf('%s-%s.%s', $image->getKey(), $this->generateHash($image), Mime::getExtensionForMimeType($image->mime_type));
     // Download file
     $this->s3->getObject(array('Bucket' => $this->awsBucket, 'Key' => $originalPath, 'SaveAs' => $tempOriginalPath));
     return new File($tempOriginalPath);
 }
Beispiel #4
0
 /**
  * @param Image $image
  * @param array $filters
  * @return string
  */
 protected function generateFileName(Image $image, array $filters = [])
 {
     return sprintf('%s-%s.%s', $image->getKey(), $this->generateHash($image, $filters), Mime::getExtensionForMimeType($image->mime_type));
 }
Beispiel #5
0
 /**
  * Tells the driver to prepare a copy of the original image locally.
  *
  * @param Image $image
  * @return File
  * @throws \Exception
  */
 public function tempOriginal(Image $image)
 {
     $originalPath = sprintf('%s/%s-%s.%s', $this->root, $image->getKey(), $this->generateHash($image), Mime::getExtensionForMimeType($image->mime_type));
     $tempOriginalPath = tempnam(sys_get_temp_dir(), null);
     if (!copy($originalPath, $tempOriginalPath)) {
         throw new \Exception('Imager couldn\'t copy the original image to the temporary location');
     }
     return new File($tempOriginalPath);
 }