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); }
/** * @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(); }
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; } } }
/** * @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)); }
/** * 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); }
/** * 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); }