Parallel Thumbnail Generation

This commit is contained in:
seiichiro 2024-02-24 18:58:34 +01:00
parent 6215ab9f5b
commit b175d77c7b
3 changed files with 37 additions and 12 deletions

View file

@ -2,7 +2,6 @@
// Classes
require_once('lib/helpers.class.php');
require_once('lib/thumbs.class.php');
require_once('lib/template.class.php');
// Settings
@ -10,9 +9,7 @@ require('conf/config.php');
// Prepare Some Basic Variables
$imagedir = Helpers::end_dir($conf['fs_imagedir']);
$thumbdir = Helpers::end_dir($conf['fs_thumbdir']);
$imageurl = Helpers::end_dir($conf['web_imagedir']);
$thumburl = Helpers::end_dir($conf['web_thumbdir']);
$galleryname = $conf['gallery_name'];
@ -41,9 +38,6 @@ $secure = ($proto == 'https');
session_set_cookie_params([ 'lifetime' => 3600, 'path' => '/', 'domain' => $host, 'secure' => $secure, 'httponly' => true, 'samesite' => 'lax' ]);
session_start();
// Initialize Thumbnail Handler
$t = new Thumb(Helpers::end_dir($imagedir.$dir), $thumbdir, $thumburl, 200, 200);
// Filelist Cache Handling
$cdir = $dir;
if (empty($cdir))
@ -142,7 +136,7 @@ if (!empty($curfiles)| !empty($dirs)) {
} else {
$tmp['n'] = $image;
$tmp['i'] = $index+1;
$tmp['t'] = $t->get_thumb($image);
$tmp['t'] = 'thumb.php?d='.Helpers::end_dir($imagedir.$dir).'&i='.$image;
$data['images'][] = $tmp;
}
}

View file

@ -3,7 +3,6 @@
class thumb {
protected string $imagedir;
protected string $thumbdir;
protected string $thumburl;
protected int $w = 200;
protected int $h = 200;
@ -26,10 +25,9 @@ class thumb {
]
];
public function __construct($idir, $tdir, $turl, $width, $heigth) {
public function __construct($idir, $tdir, $width, $heigth) {
$this->imagedir = $idir;
$this->thumbdir = $tdir;
$this->thumburl = $turl;
$this->w = $width;
$this->h = $heigth;
}
@ -52,7 +50,7 @@ class thumb {
if ($retval) {
return "img/video.png";
} else {
return $this->thumburl.$dstname.'.jpg';
return $dstpath;
}
}
@ -92,7 +90,7 @@ class thumb {
imagedestroy($image);
imagedestroy($thumbnail);
}
return $this->thumburl.$dstname.'.jpg';
return $dstpath;
}
}

33
thumb.php Normal file
View file

@ -0,0 +1,33 @@
<?php
// Load Helper Classes
require_once('lib/helpers.class.php');
require_once('lib/template.class.php');
require_once('lib/thumbs.class.php');
// Settings
require('conf/config.php');
// Prepare Some Basic Variables
$thumbdir = Helpers::end_dir($conf['fs_thumbdir']);
$imagedir = Helpers::end_dir($conf['fs_imagedir']);
// Prepare Path Traversal Check
$r_basedir=realpath($imagedir);
$dir = $_GET['d'];
$img = $_GET['i'];
$r_imagedir = realpath($dir);
if ($r_imagedir === false || strpos(Helpers::end_dir($r_imagedir), $r_basedir.DIRECTORY_SEPARATOR) !== 0) {
$data['script'] = $_SERVER['PHP_SELF'];
$data['errormsg'] = 'A Path Traversal was Detected';
Template::view('tpl/error.html', $data);
exit();
}
// Initialize Thumbnail Handler
$t = new Thumb(Helpers::end_dir($dir), $thumbdir, 200, 200);
$thumbfile = $t->get_thumb($img);
header('Content-Type: image/jpeg');
readfile($thumbfile);