forked from Adleraci/adlerka.top
Stuff
This commit is contained in:
@@ -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"];
|
||||
|
Reference in New Issue
Block a user