Compare commits
4
Commits
782c5b4b38
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
519611d06b | ||
|
|
a0580ad085 | ||
|
|
e2cf30a307 | ||
|
|
a9e8b61e0b |
No files matched your search
@@ -25,7 +25,7 @@ try {
|
||||
header("Cache-Control: max-age=86400, public");
|
||||
echo $image;
|
||||
} catch (\Exception $e) {
|
||||
$logger->error($e->getMessage());
|
||||
$logger->error($e->getMessage(), ['exception' => $e, 'path' => $imgPath, 'params' => $params]);
|
||||
http_response_code(500);
|
||||
echo "Internal Server Error";
|
||||
}
|
||||
@@ -48,6 +48,7 @@ class Resizer
|
||||
private function createVariant(Image $original, ResizeParams $params): string
|
||||
{
|
||||
$quality = $params->quality ?: -1;
|
||||
$this->logger->info("Resizing image", ['params'=>$params]);
|
||||
|
||||
$original->toWidth($params->width ?? intval($_ENV["DEFAULT_WIDTH"]));
|
||||
|
||||
|
||||
@@ -24,24 +24,32 @@ class SqliteImageDb implements ImageDb {
|
||||
quality INTEGER NULLABLE,
|
||||
content TEXT NOT NULL
|
||||
)');
|
||||
|
||||
// Create a unique index on the path and params
|
||||
$this->db->exec('CREATE UNIQUE INDEX IF NOT EXISTS images_path_width_height_quality ON images (path, width, height, quality)');
|
||||
}
|
||||
|
||||
public function findImage(string $path, ResizeParams $params): Image | null {
|
||||
$query = "SELECT * FROM images WHERE path = :path";
|
||||
$query .= $params->width ? " AND width = :width" : " AND width IS NULL";
|
||||
$query .= $params->height ? " AND height = :height" : " AND height IS NULL";
|
||||
$query .= $params->quality ? " AND quality = :quality" : " AND quality IS NULL";
|
||||
$query = 'SELECT * FROM images WHERE path = :path';
|
||||
$query .= $params->width ? ' AND width = :width' : ' AND width IS NULL';
|
||||
$query .= $params->height ? ' AND height = :height' : ' AND height IS NULL';
|
||||
$query .= $params->quality ? ' AND quality = :quality' : ' AND quality IS NULL';
|
||||
|
||||
$stmt = $this->db->prepare($query);
|
||||
$stmt->execute([
|
||||
|
||||
$queryParams = [
|
||||
':path' => $path,
|
||||
':width' => $params->width,
|
||||
':height' => $params->height,
|
||||
':quality' => $params->quality
|
||||
]);
|
||||
];
|
||||
if ($params->width !== null) $queryParams[':width'] = $params->width;
|
||||
if ($params->height !== null) $queryParams[':height'] = $params->height;
|
||||
if ($params->quality !== null) $queryParams[':quality'] = $params->quality;
|
||||
|
||||
$stmt->execute($queryParams);
|
||||
|
||||
$this->logger->info("Querying images", ['query' => $stmt->queryString]);
|
||||
|
||||
$stmt->execute();
|
||||
|
||||
$result = $stmt->fetchObject();
|
||||
|
||||
return $result ? Image::fromString(base64_decode($result->content)) : null;
|
||||
|
||||
@@ -12,7 +12,7 @@ class ResizeParams
|
||||
|
||||
public function __construct(array $params)
|
||||
{
|
||||
$this->width = intval($params['width']) ?: intval($_ENV["DEFAULT_WIDTH"]);
|
||||
$this->width = isset($params['width']) ? intval($params['width']) : intval($_ENV["DEFAULT_WIDTH"]);
|
||||
$this->height = intval($params['height']) ?: null;
|
||||
$this->quality = isset($params['quality']) ? intval($params['quality']) : null;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user