Resources encoded version

This commit is contained in:
Martijn de Boer 2024-03-23 14:36:10 +01:00
parent fd40c9cbed
commit fe2bc24465
2 changed files with 30 additions and 33 deletions

View File

@ -114,9 +114,10 @@ class Cache {
$cacheFile = PUBLIC_CACHE_DIR . "/" . $name;
$blurhash = self::generateBlurHash($cacheFile, $img, $skipExtensionCheck);
$blurhashImage = self::getBlurHashImage($blurhash);
$resourceSql = "INSERT OR REPLACE INTO `resources` (`name`, `type`, `blurhash`, `url`, `width`, `height`, `hasBeenProcessed`, `modified`)
VALUES (:name,:type,:blurhash,:url,:width,:height,1,strftime('%Y-%m-%d %H:%M:%S','now'))";
$resourceSql = "INSERT OR REPLACE INTO `resources` (`name`, `type`, `blurhash`, `url`, `width`, `height`, `hasBeenProcessed`, `modified`, `hasEncodedVersion`, `encodedVersion`)
VALUES (:name,:type,:blurhash,:url,:width,:height,1,strftime('%Y-%m-%d %H:%M:%S','now'),1,:blurhashImage)";
$db = new Database();
$resourceStmt = $db::$handle->prepare($resourceSql);
@ -126,6 +127,7 @@ class Cache {
$resourceStmt->bindValue(":url", PUBLIC_CACHE_URL . "/" . $name);
$resourceStmt->bindValue(":width", $img->getImageWidth());
$resourceStmt->bindValue(":height", $img->getImageHeight());
$resourceStmt->bindValue(":blurhashImage", $blurhashImage);
$resourceStmt->execute();
// Append to the resource cache
@ -163,15 +165,6 @@ class Cache {
}
public static function generateBlurHash(string $cacheFile, ?IMagick $img = null, bool $skipExtensionCheck = false):?string {
$ext = substr($cacheFile, strrpos($cacheFile, ".") + 1);
if ($skipExtensionCheck || strtolower($ext) == "jpg" || strtolower($ext) == "jpeg" || strtolower($ext) == "png" || strtolower($ext) == "webp") {
$hashFile = strtolower($cacheFile);
$hashFileName = substr($hashFile, strrpos($hashFile, "/") + 1);
if (file_exists($hashFile)) {
return null;
}
$pixels = [];
if ($img === null) {
@ -196,7 +189,6 @@ class Cache {
return $hash;
}
}
public static function getBlurHashImage($blurhash,$width = 269, $height = 173) {

5
schema/resources-001.sql Normal file
View File

@ -0,0 +1,5 @@
ALTER TABLE `resources` ADD COLUMN `hasEncodedVersion` INTEGER DEFAULT 0;
ALTER TABLE `resources` ADD COLUMN `encodedVersion` TEXT DEFAULT NULL;
CREATE INDEX IF NOT EXISTS `resources_hasEncodedVersion` ON `resources` (`hasEncodedVersion`);
CREATE INDEX IF NOT EXISTS `resources_blurhash_hasEncodedVersion` ON `resources` (`blurhash`, `hasEncodedVersion`);