2025-03-21 01:38:05 +01:00
|
|
|
<?php
|
|
|
|
namespace Vichan\Data;
|
|
|
|
|
|
|
|
class Exif {
|
|
|
|
public const EXIF_ORIENTATION_0_UPRIGHT = 1;
|
|
|
|
public const EXIF_ORIENTATION_0_FLIPPED = 2;
|
|
|
|
public const EXIF_ORIENTATION_180_UPRIGHT = 3;
|
|
|
|
public const EXIF_ORIENTATION_180_FLIPPED = 4;
|
|
|
|
public const EXIF_ORIENTATION_90_UPRIGHT = 5;
|
|
|
|
public const EXIF_ORIENTATION_90_FLIPPED = 6;
|
|
|
|
public const EXIF_ORIENTATION_270_UPRIGHT = 7;
|
|
|
|
public const EXIF_ORIENTATION_270_FLIPPED = 8;
|
|
|
|
public const EXIF_ORIENTATION_UNDEFINED = 9;
|
2025-03-21 01:44:50 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Should you switch width and height since the image is on the side?
|
|
|
|
*
|
|
|
|
* @param int $exif_orientation An EXIF_ORIENTATION_* constant.
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public static function exifOrientationOnSide(int $exif_orientation): bool {
|
|
|
|
return $exif_orientation >= 5 && $exif_orientation <= 8;
|
|
|
|
}
|
2025-03-22 01:47:50 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
|
|
|
}
|
2025-03-21 01:38:05 +01:00
|
|
|
}
|