#41: Read and display more photographer-specific details
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Album;
|
||||
use App\AlbumSources\IAlbumSource;
|
||||
use App\Helpers\FileHelper;
|
||||
use App\Helpers\ImageHelper;
|
||||
use App\Helpers\MiscHelper;
|
||||
use App\Helpers\ThemeHelper;
|
||||
use App\Photo;
|
||||
use Symfony\Component\HttpFoundation\File\File;
|
||||
@@ -68,18 +69,23 @@ class PhotoService
|
||||
$this->photo->mime_type = $imageInfo['mime'];
|
||||
|
||||
// Read the Exif data
|
||||
$exifData = @exif_read_data($photoFile);
|
||||
$isExifDataFound = ($exifData !== false && is_array($exifData));
|
||||
|
||||
if (is_null($this->photo->raw_exif_data))
|
||||
if (empty($this->photo->raw_exif_data))
|
||||
{
|
||||
$exifData = @exif_read_data($photoFile);
|
||||
$isExifDataFound = ($exifData !== false && is_array($exifData));
|
||||
$this->photo->raw_exif_data = $isExifDataFound ? base64_encode(serialize($exifData)) : '';
|
||||
}
|
||||
else
|
||||
{
|
||||
$exifData = unserialize(base64_decode($this->photo->raw_exif_data));
|
||||
$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']))
|
||||
// If Exif data contains an Orientation, ensure we rotate the original image as such (providing we don't
|
||||
// currently have a metadata version - i.e. it hasn't been read and rotated already before)
|
||||
if ($isExifDataFound && isset($exifData['Orientation']) && is_null($this->photo->metadata_version))
|
||||
{
|
||||
switch ($exifData['Orientation'])
|
||||
{
|
||||
@@ -117,6 +123,10 @@ class PhotoService
|
||||
$this->photo->camera_make = $this->metadataCameraMake($exifData, $this->photo->camera_make);
|
||||
$this->photo->camera_model = $this->metadataCameraModel($exifData, $this->photo->camera_model);
|
||||
$this->photo->camera_software = $this->metadataCameraSoftware($exifData, $this->photo->camera_software);
|
||||
$this->photo->aperture_fnumber = $this->metadataApertureFNumber($exifData, $this->photo->aperture_fnumber);
|
||||
$this->photo->iso_number = $this->metadataIsoNumber($exifData, $this->photo->iso_number);
|
||||
$this->photo->focal_length = $this->metadataFocalLength($exifData, $this->photo->focal_length);
|
||||
$this->photo->shutter_speed = $this->metadataExposureTime($exifData, $this->photo->shutter_speed);
|
||||
}
|
||||
|
||||
$this->photo->is_analysed = true;
|
||||
@@ -288,6 +298,22 @@ class PhotoService
|
||||
@unlink($photoPath);
|
||||
}
|
||||
|
||||
private function calculateValueFromFraction($input)
|
||||
{
|
||||
$split = explode('/', $input);
|
||||
if (count($split) != 2)
|
||||
{
|
||||
return $split;
|
||||
}
|
||||
|
||||
$numerator = intval($split[0]);
|
||||
$denominator = intval($split[1]);
|
||||
|
||||
return $denominator == 0
|
||||
? 0
|
||||
: ($numerator / $denominator);
|
||||
}
|
||||
|
||||
private function downloadToTemporaryFolder()
|
||||
{
|
||||
$photoPath = tempnam(sys_get_temp_dir(), 'BlueTwilight_');
|
||||
@@ -306,6 +332,23 @@ class PhotoService
|
||||
return $photoPath;
|
||||
}
|
||||
|
||||
private function metadataApertureFNumber(array $exifData, $originalValue = null)
|
||||
{
|
||||
if (isset($exifData['FNumber']))
|
||||
{
|
||||
$value = $this->calculateValueFromFraction($exifData['FNumber']);
|
||||
|
||||
if (intval($value) === $value)
|
||||
{
|
||||
return sprintf('f/%d', $value);
|
||||
}
|
||||
|
||||
return sprintf('f/%0.1f', $value);
|
||||
}
|
||||
|
||||
return $originalValue;
|
||||
}
|
||||
|
||||
private function metadataCameraMake(array $exifData, $originalValue = null)
|
||||
{
|
||||
if (isset($exifData['Make']))
|
||||
@@ -355,4 +398,36 @@ class PhotoService
|
||||
|
||||
return preg_replace('/^([\d]{4}):([\d]{2}):([\d]{2})/', '$1-$2-$3', $dateTime);
|
||||
}
|
||||
|
||||
private function metadataExposureTime(array $exifData, $originalValue = null)
|
||||
{
|
||||
if (isset($exifData['ExposureTime']))
|
||||
{
|
||||
$decimal = $this->calculateValueFromFraction($exifData['ExposureTime']);
|
||||
$fraction = MiscHelper::decimalToFraction($decimal);
|
||||
return sprintf('%d/%d', $fraction[0], $fraction[1]);
|
||||
}
|
||||
|
||||
return $originalValue;
|
||||
}
|
||||
|
||||
private function metadataFocalLength(array $exifData, $originalValue = null)
|
||||
{
|
||||
if (isset($exifData['FocalLength']))
|
||||
{
|
||||
return $this->calculateValueFromFraction($exifData['FocalLength']);
|
||||
}
|
||||
|
||||
return $originalValue;
|
||||
}
|
||||
|
||||
private function metadataIsoNumber(array $exifData, $originalValue = null)
|
||||
{
|
||||
if (isset($exifData['ISOSpeedRatings']))
|
||||
{
|
||||
return $exifData['ISOSpeedRatings'];
|
||||
}
|
||||
|
||||
return $originalValue;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user