Skip to content

Commit

Permalink
move svg conversion to the frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
ellite committed Jul 9, 2024
1 parent 28c8a96 commit 49cf597
Show file tree
Hide file tree
Showing 2 changed files with 224 additions and 195 deletions.
24 changes: 2 additions & 22 deletions endpoints/subscription/add.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function sanitizeFilename($filename)

function validateFileExtension($fileExtension)
{
$allowedExtensions = ['png', 'jpg', 'jpeg', 'gif', 'webp', 'svg'];
$allowedExtensions = ['png', 'jpg', 'jpeg', 'gif', 'webp'];
return in_array($fileExtension, $allowedExtensions);
}

Expand Down Expand Up @@ -83,27 +83,7 @@ function resizeAndUploadLogo($uploadedFile, $uploadDir, $name, $settings)
$originalFileName = $uploadedFile['name'];
$fileExtension = pathinfo($originalFileName, PATHINFO_EXTENSION);
$fileExtension = validateFileExtension($fileExtension) ? $fileExtension : 'png';

$sanitizedFileName = $timestamp . '-' . sanitizeFilename($name);

if ($fileExtension === 'svg') {
$fileName = $sanitizedFileName . '.' . 'png';
$svgFileContents = file_get_contents($uploadedFile['tmp_name']);
$imagick = new Imagick();
$imagick->readImageBlob($svgFileContents);
$imagick->setImageFormat("png");
$imagick->setImageCompressionQuality(90);
$imageBlob = $imagick->getImageBlob();
$imagick->clear();
$imagick->destroy();
$tempPngPath = tempnam(sys_get_temp_dir(), 'conv') . '.png';
file_put_contents($tempPngPath, $imageBlob);
$image = imagecreatefrompng($tempPngPath);
unlink($tempPngPath);
} else {
$fileName = $sanitizedFileName . '.' . $fileExtension;
}

$fileName = $timestamp . '-' . sanitizeFilename($name) . '.' . $fileExtension;
$uploadFile = $uploadDir . $fileName;

if (move_uploaded_file($uploadedFile['tmp_name'], $uploadFile)) {
Expand Down
Loading

0 comments on commit 49cf597

Please sign in to comment.