summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-06-24 22:35:29 +0500
committerilotterytea <iltsu@alright.party>2025-06-24 22:35:29 +0500
commitc734db91064944637e361f90ed90b30d48a7d910 (patch)
tree641e8a7246039d98b13fa43b0d370460168a17e2 /lib
parent2bdd40b6320d1504bb15f48242068534482c9b54 (diff)
feat: flash (.swf) support
Diffstat (limited to 'lib')
-rw-r--r--lib/file.php8
-rw-r--r--lib/thumbnails.php10
2 files changed, 15 insertions, 3 deletions
diff --git a/lib/file.php b/lib/file.php
index fc3e38a..61c4fb8 100644
--- a/lib/file.php
+++ b/lib/file.php
@@ -4,16 +4,20 @@ include_once $_SERVER['DOCUMENT_ROOT'] . '/../config.php';
function verify_mimetype(string $file_path, string $mimetype): bool
{
$path = escapeshellarg($file_path);
+ $output = [];
+ $exitCode = 0;
if (str_starts_with($mimetype, 'image/')) {
$output = shell_exec("identify -quiet -ping $path");
return !empty($output);
} else if (str_starts_with($mimetype, 'video/') || str_starts_with($mimetype, 'audio/')) {
- $output = [];
- $exitCode = 0;
$cmd = "ffprobe -v error -i $path 2>&1";
exec($cmd, $output, $exitCode);
return $exitCode === 0;
+ } else if ($mimetype == 'application/x-shockwave-flash') {
+ $cmd = "swfdump $path 2>&1";
+ exec($cmd, $output, $exitCode);
+ return $exitCode === 0;
}
throw new RuntimeException("Illegal type for MIME verifications: $mimetype");
diff --git a/lib/thumbnails.php b/lib/thumbnails.php
index 5afc775..5e99087 100644
--- a/lib/thumbnails.php
+++ b/lib/thumbnails.php
@@ -10,7 +10,15 @@ function generate_image_thumbnail(string $src_path, string $dst_path, int $width
$result_code = null;
- exec(command: "magick $input_path -resize {$width}x{$height} -loop 0 $output_path", result_code: $result_code);
+ if (str_ends_with($src_path, ".swf")) {
+ exec(command: "swfrender $input_path -o $output_path", result_code: $result_code);
+ if ($result_code != 0) {
+ return $result_code;
+ }
+ exec(command: "magick $output_path -resize {$width}x{$height} -loop 0 $output_path", result_code: $result_code);
+ } else {
+ exec(command: "magick $input_path -resize {$width}x{$height} -loop 0 $output_path", result_code: $result_code);
+ }
return $result_code;
}