BLUE-8: The OpenStack driver now works completely with all operations - flip, rotate, refresh thumbnails. It's also possible to move photos between albums across different storage providers.
This commit is contained in:
@@ -117,7 +117,7 @@ class PhotoService
|
||||
$this->photo->save();
|
||||
|
||||
// Save the original
|
||||
$this->albumSource->saveOriginal($this->photo, $photoFile);
|
||||
$this->albumSource->saveThumbnail($this->photo, $photoFile);
|
||||
|
||||
$this->regenerateThumbnails($originalPhotoResource);
|
||||
}
|
||||
@@ -128,11 +128,11 @@ class PhotoService
|
||||
$currentSource = $this->photo->album->getAlbumSource();
|
||||
$newSource = $newAlbum->getAlbumSource();
|
||||
|
||||
// Get the current photo's path
|
||||
$file = new File($currentSource->getPathToPhoto($this->photo));
|
||||
// First export the original photo from the storage provider
|
||||
$photoPath = $this->downloadToTemporaryFolder();
|
||||
|
||||
// Save to the new album
|
||||
$newSource->saveUploadedPhoto($file, $this->photo->storage_file_name);
|
||||
$newSource->saveThumbnail($this->photo, $photoPath);
|
||||
|
||||
// Delete the original
|
||||
$this->delete();
|
||||
@@ -169,25 +169,39 @@ class PhotoService
|
||||
|
||||
public function flip($horizontal, $vertical)
|
||||
{
|
||||
// First export the original photo from the storage provider
|
||||
$photoPath = $this->downloadToTemporaryFolder();
|
||||
|
||||
$imageInfo = array();
|
||||
$photoPath = $this->albumSource->getPathToPhoto($this->photo);
|
||||
$originalPhotoImage = $this->imageHelper->openImage($photoPath, $imageInfo);
|
||||
if ($this->imageHelper->flipImage($originalPhotoImage, boolval($horizontal), boolval($vertical)))
|
||||
{
|
||||
$this->imageHelper->saveImage($originalPhotoImage, $photoPath, $imageInfo);
|
||||
|
||||
// Update and save the original image back to the storage provider
|
||||
$this->albumSource->saveThumbnail($this->photo, $photoPath);
|
||||
|
||||
// Re-create the thumbnails
|
||||
$this->regenerateThumbnails($originalPhotoImage);
|
||||
|
||||
$this->photo->save();
|
||||
}
|
||||
|
||||
// Remove the temp file
|
||||
@unlink($photoPath);
|
||||
}
|
||||
|
||||
public function regenerateThumbnails($originalPhotoResource = null)
|
||||
{
|
||||
$photoPath = null;
|
||||
|
||||
if (is_null($originalPhotoResource))
|
||||
{
|
||||
// First export the original photo from the storage provider
|
||||
$photoPath = $this->downloadToTemporaryFolder();
|
||||
|
||||
$imageInfo = null;
|
||||
$originalPhotoResource = $this->imageHelper->openImage($this->albumSource->getPathToPhoto($this->photo), $imageInfo);
|
||||
$originalPhotoResource = $this->imageHelper->openImage($photoPath, $imageInfo);
|
||||
}
|
||||
|
||||
// Generate and save thumbnails
|
||||
@@ -200,16 +214,28 @@ class PhotoService
|
||||
$generatedThumbnailPath = $this->imageHelper->generateThumbnail($originalPhotoResource, $this->photo, $thumbnail);
|
||||
$this->albumSource->saveThumbnail($this->photo, $generatedThumbnailPath, $thumbnail['name']);
|
||||
}
|
||||
|
||||
if (is_null($originalPhotoResource) && !is_null($photoPath))
|
||||
{
|
||||
// Remove the temp file
|
||||
@unlink($photoPath);
|
||||
}
|
||||
}
|
||||
|
||||
public function rotate($angle)
|
||||
{
|
||||
$imageInfo = array();
|
||||
$photoPath = $this->albumSource->getPathToPhoto($this->photo);
|
||||
|
||||
// First export the photo from the storage provider
|
||||
$photoPath = $this->downloadToTemporaryFolder();
|
||||
|
||||
$originalPhotoImage = $this->imageHelper->openImage($photoPath, $imageInfo);
|
||||
$originalPhotoImage = $this->imageHelper->rotateImage($originalPhotoImage, intval($angle));
|
||||
$this->imageHelper->saveImage($originalPhotoImage, $photoPath, $imageInfo);
|
||||
|
||||
// Update and save the original image back to the storage provider
|
||||
$this->albumSource->saveThumbnail($this->photo, $photoPath);
|
||||
|
||||
if ($angle == 90 || $angle == 270)
|
||||
{
|
||||
$width = $this->photo->width;
|
||||
@@ -220,6 +246,27 @@ class PhotoService
|
||||
$this->regenerateThumbnails($originalPhotoImage);
|
||||
|
||||
$this->photo->save();
|
||||
|
||||
// Remove the temp file
|
||||
@unlink($photoPath);
|
||||
}
|
||||
|
||||
private function downloadToTemporaryFolder()
|
||||
{
|
||||
$photoPath = tempnam(sys_get_temp_dir(), 'BlueTwilight_');
|
||||
$photoHandle = fopen($photoPath, 'w');
|
||||
|
||||
$stream = $this->albumSource->fetchPhotoContent($this->photo);
|
||||
$stream->rewind();
|
||||
while (!$stream->feof())
|
||||
{
|
||||
fwrite($photoHandle, $stream->read(4096));
|
||||
}
|
||||
fflush($photoHandle);
|
||||
fclose($photoHandle);
|
||||
$stream->close();
|
||||
|
||||
return $photoPath;
|
||||
}
|
||||
|
||||
private function metadataCameraMake(array $exifData)
|
||||
|
||||
Reference in New Issue
Block a user