fix: retrieve metadata for thumbnail overlay
This commit is contained in:
parent
663243e956
commit
2745e1cc35
1 changed files with 19 additions and 0 deletions
19
new.php
19
new.php
|
|
@ -47,6 +47,20 @@ function ascii_safe($s){
|
|||
}
|
||||
function slugify($s){ $s = ascii_safe($s); $s = strtolower(trim($s)); $s = preg_replace('/[^a-z0-9]+/', '-', $s); return trim($s, '-') ?: 'movie'; }
|
||||
function rrmdir($dir){ if(!is_dir($dir)) return; foreach(scandir($dir) as $f){ if($f==='.'||$f==='..') continue; $p="$dir/$f"; is_dir($p)?rrmdir($p):unlink($p);} rmdir($dir); }
|
||||
function apply_thumbnail_overlay($imagePath, $title, $teaser) {
|
||||
$fontPath = __DIR__ . '/assets/fonts/IBMPlexSans-SemiBold.ttf';
|
||||
$cmd = sprintf(
|
||||
'convert %s -font %s -pointsize 30 -fill "#F3F4F6" -gravity northwest -annotate +20+20 %s -font %s -pointsize 20 -fill "#EADFC9" -gravity northwest -annotate +20+60 %s %s',
|
||||
escapeshellarg($imagePath),
|
||||
escapeshellarg($fontPath),
|
||||
escapeshellarg($title),
|
||||
escapeshellarg($fontPath),
|
||||
escapeshellarg($teaser),
|
||||
escapeshellarg($imagePath)
|
||||
);
|
||||
shell_exec($cmd);
|
||||
}
|
||||
|
||||
function input_dirs($base){ return glob($base.'/*', GLOB_ONLYDIR) ?: []; }
|
||||
function safe_input_dir($base, $name){ $name = basename((string)$name); $path = realpath($base . '/' . $name); $root = realpath($base); if (!$path || !$root || !str_starts_with($path, $root . DIRECTORY_SEPARATOR) || !is_dir($path)) throw new RuntimeException('Invalid input directory.'); return $path; }
|
||||
function article_id_is_valid($id){ return is_string($id) && preg_match('/^[0-9]{14}[a-f0-9]{16}$/', $id); }
|
||||
|
|
@ -852,6 +866,7 @@ try {
|
|||
$file = basename((string)($_POST['file'] ?? ''));
|
||||
if ($file === '' || !is_image_media_file($file) || !is_file($dir . '/' . $file)) throw new RuntimeException('Invalid image file.');
|
||||
$state = input_dir_state($dir);
|
||||
$meta = read_data($dir); // Need this for title and teaser
|
||||
$outputs = [];
|
||||
foreach (['output', 'preview_output'] as $key) {
|
||||
$name = basename((string)($state[$key] ?? ''));
|
||||
|
|
@ -874,6 +889,10 @@ try {
|
|||
$target = $config['videos_dir'] . '/' . $base . '_thumb.jpg';
|
||||
if (!@copy($src, $target)) throw new RuntimeException('Failed to write thumbnail.');
|
||||
@chmod($target, 0664);
|
||||
|
||||
// Apply text overlay
|
||||
apply_thumbnail_overlay($target, $meta['title'], $meta['teaser']);
|
||||
|
||||
$written[] = basename($target);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue