Resources encoded version
This commit is contained in:
parent
fd40c9cbed
commit
fe2bc24465
2 changed files with 30 additions and 33 deletions
|
@ -114,9 +114,10 @@ class Cache {
|
||||||
$cacheFile = PUBLIC_CACHE_DIR . "/" . $name;
|
$cacheFile = PUBLIC_CACHE_DIR . "/" . $name;
|
||||||
|
|
||||||
$blurhash = self::generateBlurHash($cacheFile, $img, $skipExtensionCheck);
|
$blurhash = self::generateBlurHash($cacheFile, $img, $skipExtensionCheck);
|
||||||
|
$blurhashImage = self::getBlurHashImage($blurhash);
|
||||||
|
|
||||||
$resourceSql = "INSERT OR REPLACE INTO `resources` (`name`, `type`, `blurhash`, `url`, `width`, `height`, `hasBeenProcessed`, `modified`)
|
$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'))";
|
VALUES (:name,:type,:blurhash,:url,:width,:height,1,strftime('%Y-%m-%d %H:%M:%S','now'),1,:blurhashImage)";
|
||||||
|
|
||||||
$db = new Database();
|
$db = new Database();
|
||||||
$resourceStmt = $db::$handle->prepare($resourceSql);
|
$resourceStmt = $db::$handle->prepare($resourceSql);
|
||||||
|
@ -126,6 +127,7 @@ class Cache {
|
||||||
$resourceStmt->bindValue(":url", PUBLIC_CACHE_URL . "/" . $name);
|
$resourceStmt->bindValue(":url", PUBLIC_CACHE_URL . "/" . $name);
|
||||||
$resourceStmt->bindValue(":width", $img->getImageWidth());
|
$resourceStmt->bindValue(":width", $img->getImageWidth());
|
||||||
$resourceStmt->bindValue(":height", $img->getImageHeight());
|
$resourceStmt->bindValue(":height", $img->getImageHeight());
|
||||||
|
$resourceStmt->bindValue(":blurhashImage", $blurhashImage);
|
||||||
$resourceStmt->execute();
|
$resourceStmt->execute();
|
||||||
|
|
||||||
// Append to the resource cache
|
// Append to the resource cache
|
||||||
|
@ -163,15 +165,6 @@ class Cache {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function generateBlurHash(string $cacheFile, ?IMagick $img = null, bool $skipExtensionCheck = false):?string {
|
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 = [];
|
$pixels = [];
|
||||||
|
|
||||||
if ($img === null) {
|
if ($img === null) {
|
||||||
|
@ -196,7 +189,6 @@ class Cache {
|
||||||
|
|
||||||
return $hash;
|
return $hash;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static function getBlurHashImage($blurhash,$width = 269, $height = 173) {
|
public static function getBlurHashImage($blurhash,$width = 269, $height = 173) {
|
||||||
|
|
||||||
|
|
5
schema/resources-001.sql
Normal file
5
schema/resources-001.sql
Normal 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`);
|
Loading…
Reference in a new issue