From 1a82462d0af1ed49fc56850500a6ace8fccb6931 Mon Sep 17 00:00:00 2001 From: Zankaria Date: Sat, 22 Mar 2025 01:47:50 +0100 Subject: [PATCH] Exif.php: add helper query functions --- inc/Data/Exif.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/inc/Data/Exif.php b/inc/Data/Exif.php index caf9bb82..093998a9 100644 --- a/inc/Data/Exif.php +++ b/inc/Data/Exif.php @@ -21,4 +21,40 @@ class Exif { public static function exifOrientationOnSide(int $exif_orientation): bool { return $exif_orientation >= 5 && $exif_orientation <= 8; } + + /** + * Gives the rotation in degrees of the given exif orientation. + * + * @param int $exif_orientation One of the EXIF_ORIENTATION_* constants. + * @return int Rotation in degrees. + */ + public static function exifOrientationDegrees(int $exif_orientation): int { + switch ($exif_orientation) { + case self::EXIF_ORIENTATION_UNDEFINED: + case self::EXIF_ORIENTATION_0_UPRIGHT: + case self::EXIF_ORIENTATION_0_FLIPPED: + return 0; + case self::EXIF_ORIENTATION_180_UPRIGHT: + case self::EXIF_ORIENTATION_180_FLIPPED: + return 180; + case self::EXIF_ORIENTATION_90_UPRIGHT: + case self::EXIF_ORIENTATION_90_FLIPPED: + return 90; + case self::EXIF_ORIENTATION_270_UPRIGHT: + case self::EXIF_ORIENTATION_270_FLIPPED: + return 270; + default: + throw new \RuntimeException("Invalid exif orientation '$exif_orientation'"); + } + } + + /** + * If the given exif orientation flips the image. + * + * @param int $exif_orientation One of the EXIF_ORIENTATION_* constants. + * @return bool If the image is flipped. + */ + public static function exifOrientationIsFlipped(int $exif_orientation): bool { + return $exif_orientation % 2 == 0; + } }