From 9eae0a8eeea6eecf5e8cf6477159b39e5db3202e Mon Sep 17 00:00:00 2001 From: Martijn de Boer Date: Fri, 22 Mar 2024 18:25:03 +0100 Subject: [PATCH] fix webp --- lib/Cache.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/Cache.php b/lib/Cache.php index 8755fa5..132fec4 100644 --- a/lib/Cache.php +++ b/lib/Cache.php @@ -79,7 +79,7 @@ class Cache { $name = strtolower($name); $ext = substr($name, strrpos($name, ".") + 1); - if ($skipExtensionCheck || strtolower($ext) == "jpg" || strtolower($ext) == "jpeg" || strtolower($ext) == "png") { + if ($skipExtensionCheck || strtolower($ext) == "jpg" || strtolower($ext) == "jpeg" || strtolower($ext) == "png" || strtolower($ext) == "webp"){ $size = strlen($data); $img = new Imagick(); $img->readImageBlob($data); @@ -90,9 +90,10 @@ class Cache { $name = str_replace("." . $ext, ".webp", strtolower($name)); $cacheFile = PUBLIC_CACHE_DIR . "/" . $name; + $blurhash = self::generateBlurHash($cacheFile, $img, $skipExtensionCheck); - $resourceSql = "INSERT INTO `resources` (`name`, `type`, `blurhash`, `url`, `width`, `height`, `hasBeenProcessed`, `modified`) + $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'))"; $db = new Database(); @@ -119,7 +120,7 @@ class Cache { // For now don't transfer file if its generated name exists if (file_exists($cacheFile)) { - Logger::log("Public cache file " . $name . " already exists", Logger::INFO, "Cache"); + //Logger::log("Public cache file " . $name . " already exists", Logger::INFO, "Cache"); return PUBLIC_CACHE_URL . "/" . $name; } @@ -177,6 +178,10 @@ class Cache { public static function getBlurHashImage($blurhash,$width = 269, $height = 173) { + if (empty($blurhash)) { + return "data:image/jpg;base64,/9j/7gAhQWRvYmUAZIAAAAABAwAQAwIDBgAAAAAAAAAAAAAAAP/bAIQAEg4ODhAOFRAQFR4TERMeIxoVFRojIhcXFxcXIhEMDAwMDAwRDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAEUExMWGRYbFxcbFA4ODhQUDg4ODhQRDAwMDAwREQwMDAwMDBEMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwM/8IAEQgAAwAEAwEiAAIRAQMRAf/EAF4AAQEBAAAAAAAAAAAAAAAAAAAEBwEBAAAAAAAAAAAAAAAAAAAABBABAAAAAAAAAAAAAAAAAAAAABEBAAAAAAAAAAAAAAAAAAAAABIBAAAAAAAAAAAAAAAAAAAAAP/aAAwDAQECEQMRAAAAsZ0Kj//aAAgBAgABBQB//9oACAEDAAEFAH//2gAIAQEAAQUAf//aAAgBAgIGPwB//9oACAEDAgY/AH//2gAIAQEBBj8Af//Z"; + } + $hash = \kornrunner\Blurhash\Blurhash::decode($blurhash, $width, $height); $img = new Imagick();