Inheritance: extends Illuminate\Database\Eloquent\Model
Ejemplo n.º 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);
 }
Ejemplo n.º 2
0
 /**
  * @param $slot
  * @param Imageable $imageable
  * @return \TippingCanoe\Imager\Model\Image
  */
 public function getBySlot($slot, Imageable $imageable = null)
 {
     if ($imageable) {
         $query = ImageModel::forImageable(get_class($imageable), $imageable->getKey());
     } else {
         $query = ImageModel::unattached();
     }
     return $query->inSlot($slot)->first();
 }
Ejemplo n.º 3
0
 public function moveToSlot(Image $image, $slot)
 {
     try {
         // Assign the new slot to our image.
         $image->slot = $slot;
         $image->save();
     } catch (Exception $ex) {
         // Move the previous image out temporarily, we'll perform a swap.
         $previousSlotImage = $this->getBySlot($slot, $image->imageble);
         $previousSlotImage->slot = null;
         $previousSlotImage->save();
         // Save the slot our image is in.
         $previousSlot = $image->slot;
         // NOW save!
         $image->slot = $slot;
         $image->save();
         // If our image had a non-null slot, move the previous occupant of the target slot into it.
         if ($previousSlot !== null) {
             $previousSlotImage->slot = $previousSlot;
             $previousSlotImage->save;
         }
     }
 }
Ejemplo n.º 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));
 }
Ejemplo n.º 5
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);
 }
Ejemplo n.º 6
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);
 }