diff --git a/app/ModelFunctions/PhotoFunctions.php b/app/ModelFunctions/PhotoFunctions.php index 09c5da676d2..aca69ed4aa9 100644 --- a/app/ModelFunctions/PhotoFunctions.php +++ b/app/ModelFunctions/PhotoFunctions.php @@ -89,66 +89,6 @@ public function __construct(Extractor $metadataExtractor, ImageHandlerInterface $this->sessionFunctions = $sessionFunctions; } - /** - * @param Photo $photo - * - * @return string Path of the video frame - */ - public function extractVideoFrame(Photo $photo): string - { - if ($photo->aperture === '') { - return ''; - } - - $ffmpeg = FFMpeg\FFMpeg::create(); - $video = $ffmpeg->open(Storage::path('big/' . $photo->url)); - $frame = $video->frame(FFMpeg\Coordinate\TimeCode::fromSeconds($photo->aperture / 2)); - - $tmp = tempnam(sys_get_temp_dir(), 'lychee'); - Logs::notice(__METHOD__, __LINE__, 'Saving frame to ' . $tmp); - $frame->save($tmp); - - return $tmp; - } - - /** - * Create thumbnail for a picture. - * - * @param Photo $photo - * @param string Path of the video frame - * - * @return bool returns true when successful - */ - public function createThumb(Photo $photo, string $frame_tmp = '') - { - Logs::notice(__METHOD__, __LINE__, 'Photo URL is ' . $photo->url); - - $src = ($frame_tmp === '') ? Storage::path('big/' . $photo->url) : $frame_tmp; - $photoName = explode('.', $photo->url); - $this->imageHandler->crop( - $src, - Storage::path('thumb/' . $photoName[0] . '.jpeg'), - 200, - 200 - ); - - if (Configs::get_value('thumb_2x') === '1' && - $photo->width >= 400 && $photo->height >= 400) { - // Retina thumbs - $this->imageHandler->crop( - $src, - Storage::path('thumb/' . $photoName[0] . '@2x.jpeg'), - 400, - 400 - ); - $photo->thumb2x = 1; - } else { - $photo->thumb2x = 0; - } - - return true; - } - /** * Returns 'photo' if it is a photo * Returns 'video' if it is a video @@ -284,7 +224,6 @@ public function add(array $file, $albumID_in = 0, $delete_imported = false, $for $photo->checksum = $checksum; $exists = $photo->isDuplicate($checksum); - // double check that if ($exists !== false) { $photo_name = $exists->url; $path = Storage::path($path_prefix . $exists->url); @@ -384,6 +323,8 @@ public function add(array $file, $albumID_in = 0, $delete_imported = false, $for $photo->public = $public; $photo->star = $star; + $photo = $this->altitude_fix($photo); + $GoogleMicroVideoOffset = $info['MicroVideoOffset']; if ($albumID !== null) { @@ -524,6 +465,66 @@ public function createSmallerImages(Photo $photo, string $frame_tmp = '') } } + /** + * @param Photo $photo + * + * @return string Path of the video frame + */ + public function extractVideoFrame(Photo $photo): string + { + if ($photo->aperture === '') { + return ''; + } + + $ffmpeg = FFMpeg\FFMpeg::create(); + $video = $ffmpeg->open(Storage::path('big/' . $photo->url)); + $frame = $video->frame(FFMpeg\Coordinate\TimeCode::fromSeconds($photo->aperture / 2)); + + $tmp = tempnam(sys_get_temp_dir(), 'lychee'); + Logs::notice(__METHOD__, __LINE__, 'Saving frame to ' . $tmp); + $frame->save($tmp); + + return $tmp; + } + + /** + * Create thumbnail for a picture. + * + * @param Photo $photo + * @param string Path of the video frame + * + * @return bool returns true when successful + */ + public function createThumb(Photo $photo, string $frame_tmp = '') + { + Logs::notice(__METHOD__, __LINE__, 'Photo URL is ' . $photo->url); + + $src = ($frame_tmp === '') ? Storage::path('big/' . $photo->url) : $frame_tmp; + $photoName = explode('.', $photo->url); + $this->imageHandler->crop( + $src, + Storage::path('thumb/' . $photoName[0] . '.jpeg'), + 200, + 200 + ); + + if (Configs::get_value('thumb_2x') === '1' && + $photo->width >= 400 && $photo->height >= 400) { + // Retina thumbs + $this->imageHandler->crop( + $src, + Storage::path('thumb/' . $photoName[0] . '@2x.jpeg'), + 400, + 400 + ); + $photo->thumb2x = 1; + } else { + $photo->thumb2x = 0; + } + + return true; + } + /** * Creates smaller copies of Photo. * @@ -717,6 +718,30 @@ public function save(Photo $photo, $albumID) return $photo->id; } + /** + * Given the information of a photo, makes sure the altitude is in the correct range. + * + * @param Photo $photo + * + * @return Photo + */ + private function altitude_fix(Photo $photo) + { + $altitude = $photo->altitude; + // max value of dec(10,4) is 999' 999.9999 + if ($altitude > 999999.9999) { + // we are out of the bound + // we assume this is a bug due to DJI firmware not updated + // we signal the user and erase the value before adding it the database. + $photo->altitude = null; + Logs::warning(__METHOD__, __LINE__, 'altitude set to 0, previous value was out of bounds:' . $altitude . ' for picture ' . $photo->title); + Logs::warning(__METHOD__, __LINE__, $photo->url); + Logs::warning(__METHOD__, __LINE__, 'Manually parse the file with exiftool and edit the database to set the correct value.'); + } + + return $photo; + } + /** * Validates whether $type is a valid image type. *