1
0
mirror of https://github.com/janeczku/calibre-web synced 2024-11-24 18:47:23 +00:00

Fix #1255 (support webp in comic viewer)

This commit is contained in:
andylizi 2020-12-17 23:53:24 +08:00
parent 376214e2d2
commit 123493ee59
No known key found for this signature in database
GPG Key ID: 9429B030E974305F
2 changed files with 20 additions and 5 deletions

View File

@ -141,9 +141,24 @@ var createURLFromArray = function(array, mimeType) {
kthoom.ImageFile = function(file) { kthoom.ImageFile = function(file) {
this.filename = file.filename; this.filename = file.filename;
var fileExtension = file.filename.split(".").pop().toLowerCase(); var fileExtension = file.filename.split(".").pop().toLowerCase();
this.mimeType = fileExtension === "png" ? "image/png" : switch (fileExtension) {
(fileExtension === "jpg" || fileExtension === "jpeg") ? "image/jpeg" : case "jpg":
fileExtension === "gif" ? "image/gif" : fileExtension === "svg" ? "image/xml+svg" : undefined; case "jpeg":
this.mimeType = "image/jpeg";
break;
case "gif":
this.mimeType = "iamge/gif";
break;
case "svg":
this.mimeType = "image/svg+xml";
break;
case "webp":
this.mimeType = "image/webp";
break;
default:
this.mimeType = undefined;
break;
}
if ( this.mimeType !== undefined) { if ( this.mimeType !== undefined) {
this.dataURI = createURLFromArray(file.fileData, this.mimeType); this.dataURI = createURLFromArray(file.fileData, this.mimeType);
this.data = file; this.data = file;
@ -336,7 +351,7 @@ function setImage(url) {
$("#mainText").innerHTML("<iframe style=\"width:100%;height:700px;border:0\" src=\"data:text/html," + escape(xhr.responseText) + "\"></iframe>"); $("#mainText").innerHTML("<iframe style=\"width:100%;height:700px;border:0\" src=\"data:text/html," + escape(xhr.responseText) + "\"></iframe>");
}; };
xhr.send(null); xhr.send(null);
} else if (!/(jpg|jpeg|png|gif)$/.test(imageFiles[currentImage].filename) && imageFiles[currentImage].data.uncompressedSize < 10 * 1024) { } else if (!/(jpg|jpeg|png|gif|webp)$/.test(imageFiles[currentImage].filename) && imageFiles[currentImage].data.uncompressedSize < 10 * 1024) {
xhr.open("GET", url, true); xhr.open("GET", url, true);
xhr.onload = function() { xhr.onload = function() {
$("#mainText").css("display", ""); $("#mainText").css("display", "");

View File

@ -560,7 +560,7 @@ def get_comic_book(book_id, book_format, page):
else: else:
b64 = extract(page).encode('base64') b64 = extract(page).encode('base64')
ext = names[page].rpartition('.')[-1] ext = names[page].rpartition('.')[-1]
if ext not in ('png', 'gif', 'jpg', 'jpeg'): if ext not in ('png', 'gif', 'jpg', 'jpeg', 'webp'):
ext = 'png' ext = 'png'
extractedfile="data:image/" + ext + ";base64," + b64 extractedfile="data:image/" + ext + ";base64," + b64
fileData={"name": names[page], "page":page, "last":len(names)-1, "content": extractedfile} fileData={"name": names[page], "page":page, "last":len(names)-1, "content": extractedfile}