BLUE-13: improved the design and handling of the analysis screen. Also fixed bulk uploads to work since the storage changes in 1.1

This commit is contained in:
Andy Heathershaw
2016-10-30 18:36:34 +00:00
parent e3d3d4d8be
commit 5b915f911e
10 changed files with 186 additions and 66 deletions
+68 -55
View File
@@ -51,75 +51,87 @@ class PhotoService
public function analyse($queueToken)
{
$photoFile = join(DIRECTORY_SEPARATOR, [
FileHelper::getQueuePath($queueToken),
$this->photo->storage_file_name
]);
$queuePath = FileHelper::getQueuePath($queueToken);
$photoFile = join(DIRECTORY_SEPARATOR, [$queuePath, $this->photo->storage_file_name]);
$imageInfo = null;
$originalPhotoResource = $this->imageHelper->openImage($photoFile, $imageInfo);
if ($originalPhotoResource === false)
try
{
throw new \Exception(sprintf('The image "%s" does not appear to be a valid image, or cannot be read', pathinfo($photoFile, PATHINFO_FILENAME)));
}
$this->photo->width = $imageInfo[0];
$this->photo->height = $imageInfo[1];
$this->photo->mime_type = $imageInfo['mime'];
// Read the Exif data
$exifData = @exif_read_data($photoFile);
$isExifDataFound = ($exifData !== false && is_array($exifData));
$angleToRotate = 0;
// If Exif data contains an Orientation, ensure we rotate the original image as such
if ($isExifDataFound && isset($exifData['Orientation']))
{
switch ($exifData['Orientation'])
$imageInfo = null;
$originalPhotoResource = $this->imageHelper->openImage($photoFile, $imageInfo);
if ($originalPhotoResource === false)
{
case 3:
$angleToRotate = 180;
break;
case 6:
$angleToRotate = 270;
break;
case 8:
$angleToRotate = 90;
break;
throw new \Exception(sprintf('The image "%s" does not appear to be a valid image, or cannot be read', pathinfo($photoFile, PATHINFO_FILENAME)));
}
if ($angleToRotate > 0)
{
$originalPhotoResource = $this->imageHelper->rotateImage($originalPhotoResource, $angleToRotate);
$this->photo->width = $imageInfo[0];
$this->photo->height = $imageInfo[1];
$this->photo->mime_type = $imageInfo['mime'];
if ($angleToRotate == 90 || $angleToRotate == 270)
// Read the Exif data
$exifData = @exif_read_data($photoFile);
$isExifDataFound = ($exifData !== false && is_array($exifData));
$angleToRotate = 0;
// If Exif data contains an Orientation, ensure we rotate the original image as such
if ($isExifDataFound && isset($exifData['Orientation']))
{
switch ($exifData['Orientation'])
{
$this->photo->width = $imageInfo[1];
$this->photo->height = $imageInfo[0];
case 3:
$angleToRotate = 180;
break;
case 6:
$angleToRotate = 270;
break;
case 8:
$angleToRotate = 90;
break;
}
$this->imageHelper->saveImage($originalPhotoResource, $photoFile, $imageInfo);
if ($angleToRotate > 0)
{
$originalPhotoResource = $this->imageHelper->rotateImage($originalPhotoResource, $angleToRotate);
if ($angleToRotate == 90 || $angleToRotate == 270)
{
$this->photo->width = $imageInfo[1];
$this->photo->height = $imageInfo[0];
}
$this->imageHelper->saveImage($originalPhotoResource, $photoFile, $imageInfo);
}
}
}
if ($isExifDataFound)
if ($isExifDataFound)
{
$this->photo->metadata_version = self::METADATA_VERSION;
$this->photo->taken_at = $this->metadataDateTime($exifData);
$this->photo->camera_make = $this->metadataCameraMake($exifData);
$this->photo->camera_model = $this->metadataCameraModel($exifData);
$this->photo->camera_software = $this->metadataCameraSoftware($exifData);
}
$this->photo->is_analysed = true;
$this->photo->save();
// Save the original
$this->albumSource->saveThumbnail($this->photo, $photoFile);
$this->regenerateThumbnails($originalPhotoResource);
}
catch (\Exception $ex)
{
$this->photo->metadata_version = self::METADATA_VERSION;
$this->photo->taken_at = $this->metadataDateTime($exifData);
$this->photo->camera_make = $this->metadataCameraMake($exifData);
$this->photo->camera_model = $this->metadataCameraModel($exifData);
$this->photo->camera_software = $this->metadataCameraSoftware($exifData);
throw $ex;
}
finally
{
@unlink($photoFile);
$this->photo->is_analysed = true;
$this->photo->save();
// Save the original
$this->albumSource->saveThumbnail($this->photo, $photoFile);
$this->regenerateThumbnails($originalPhotoResource);
// If the queue directory is now empty, get rid of it
FileHelper::deleteIfEmpty($queuePath);
}
}
public function changeAlbum(Album $newAlbum)
@@ -213,6 +225,7 @@ class PhotoService
{
$generatedThumbnailPath = $this->imageHelper->generateThumbnail($originalPhotoResource, $this->photo, $thumbnail);
$this->albumSource->saveThumbnail($this->photo, $generatedThumbnailPath, $thumbnail['name']);
@unlink($generatedThumbnailPath);
}
if (is_null($originalPhotoResource) && !is_null($photoPath))