This commit is contained in:
2024-04-26 14:37:54 +02:00
parent 1f1e4997fa
commit f1165f2c51
6 changed files with 58 additions and 49 deletions

View File

@@ -18,6 +18,31 @@ function makePathSafe($userInput): string
return substr($safeString, 0, 255);
}
function autoRotateImage(Imagick $imagick): void {
// Get the current orientation of the image
try {
$orientation = $imagick->getImageOrientation();
switch ($orientation) {
case Imagick::ORIENTATION_BOTTOMRIGHT: // upside down
$imagick->rotateimage("#000", 180); // rotate 180 degrees
break;
case Imagick::ORIENTATION_RIGHTTOP: // 90 degrees CW
$imagick->rotateimage("#000", 90); // rotate 90 degrees CW
break;
case Imagick::ORIENTATION_LEFTBOTTOM: // 90 degrees CCW
$imagick->rotateimage("#000", -90); // rotate 90 degrees CCW
break;
}
// Reset orientation to normal after the correction
$imagick->setImageOrientation(Imagick::ORIENTATION_TOPLEFT);
} catch (ImagickException) {
}
}
function getIncomingFiles(): array
{
$files = $_FILES;
@@ -60,10 +85,11 @@ function doImageUpload($inFile, $outFile): bool
try {
$imagick = new Imagick($inFile);
$imagick->setImageFormat('webp');
autoRotateImage($imagick);
$imagick->stripImage();
$imagick->writeImage($outFile);
$imagick->destroy();
} catch (ImagickException $e) {
} catch (ImagickException) {
}
// Check if the reencoding was successful
@@ -225,20 +251,7 @@ function addToGroup(int $groupId, int $fileId): array
return $output;
}
function getImageURL(int $imageFileID): string
{
global $mysqli;
$path = "";
$stmtget = $mysqli->prepare('SELECT Path FROM Files WHERE ID = ?');
$stmtget->bind_param('i', $imageFileID);
$stmtget->execute();
$stmtget->bind_result($path);
$stmtget->fetch();
return $path;
}
function deleteFile(int $fileID): string
function deleteFile(int $fileID): array
{
global $mysqli;
$out = ["Status" => "Fail"];