From ea35faee91e82bc6d7e79881eaf8427eb7feb23f Mon Sep 17 00:00:00 2001 From: tr7zw Date: Tue, 7 Jun 2022 00:28:41 +0200 Subject: [PATCH 1/4] Add jxl support --- src/util/util.cr | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/util/util.cr b/src/util/util.cr index e08bd9d..cb53b46 100644 --- a/src/util/util.cr +++ b/src/util/util.cr @@ -11,6 +11,7 @@ SUPPORTED_IMG_TYPES = %w( image/avif image/gif image/svg+xml + image/jxl ) def random_str @@ -49,6 +50,7 @@ def register_mime_types # defiend by Crystal in `MIME.DEFAULT_TYPES` ".apng" => "image/apng", ".avif" => "image/avif", + ".jxl" => "image/jxl", }.each do |k, v| MIME.register k, v end From ae583cf2a9a2c12f099811c63c67886a651fe76d Mon Sep 17 00:00:00 2001 From: tr7zw Date: Tue, 7 Jun 2022 16:09:02 +0200 Subject: [PATCH 2/4] Workaround for "0 width/height" api responses This needs a more proper fix probably. --- public/js/reader.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/public/js/reader.js b/public/js/reader.js index a5d8e6b..11b3b49 100644 --- a/public/js/reader.js +++ b/public/js/reader.js @@ -29,14 +29,14 @@ const readerComponent = () => { return { id: i + 1, url: `${base_url}api/page/${tid}/${eid}/${i+1}`, - width: d.width, - height: d.height, + width: d.width == 0 ? "100%" : d.width, + height: d.height == 0 ? "100%" : d.height, }; }); - const avgRatio = this.items.reduce((acc, cur) => { + const avgRatio = dimensions.reduce((acc, cur) => { return acc + cur.height / cur.width - }, 0) / this.items.length; + }, 0) / dimensions.length; console.log(avgRatio); this.longPages = avgRatio > 2; From fe440d82d49bab2ea793b41046f710fd4fd335ee Mon Sep 17 00:00:00 2001 From: Alex Ling Date: Sat, 18 Jun 2022 11:10:14 +0000 Subject: [PATCH 3/4] Fix linter issue --- src/util/util.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/util/util.cr b/src/util/util.cr index cb53b46..68e26c7 100644 --- a/src/util/util.cr +++ b/src/util/util.cr @@ -50,7 +50,7 @@ def register_mime_types # defiend by Crystal in `MIME.DEFAULT_TYPES` ".apng" => "image/apng", ".avif" => "image/avif", - ".jxl" => "image/jxl", + ".jxl" => "image/jxl", }.each do |k, v| MIME.register k, v end From 31df058f8135f8191c92583f7f06557c3f1ec4e1 Mon Sep 17 00:00:00 2001 From: Alex Ling Date: Sat, 18 Jun 2022 11:25:20 +0000 Subject: [PATCH 4/4] Comment about infinity average ratio --- public/js/reader.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/public/js/reader.js b/public/js/reader.js index 11b3b49..fa66b77 100644 --- a/public/js/reader.js +++ b/public/js/reader.js @@ -34,6 +34,8 @@ const readerComponent = () => { }; }); + // Note: for image types not supported by image_size.cr, the width and height will be 0, and so `avgRatio` will be `Infinity`. + // TODO: support more image types in image_size.cr const avgRatio = dimensions.reduce((acc, cur) => { return acc + cur.height / cur.width }, 0) / dimensions.length;