-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
image.lua
55 lines (44 loc) · 1.12 KB
/
image.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
local Item = require("libs/gazette/epub/package/item")
local EpubError = require("libs/gazette/epuberror")
local util = require("util")
local Image = Item:new {
format = nil,
add_to_nav = false,
}
Image.SUPPORTED_FORMATS = {
jpeg = "image/jpeg",
jpg = "image/jpeg",
png = "image/png",
gif = "image/gif",
svg = "image/svg+xml"
}
function Image:new(o)
o = o or {}
self.__index = self
setmetatable(o, self)
if not o.path
then
return false, EpubError.ITEM_MISSING_PATH
end
-- Change "format" to "fileType" or "extension"
local format = o:isFormatSupported(o.path)
if not format
then
return false, EpubError.IMAGE_UNSUPPORTED_FORMAT
end
o.media_type = format
o:generateId()
o.path = o.path
return o
end
function Image:fetchContent(data_source)
end
function Image:isFormatSupported(path)
-- path = path and string.lower(path) or ""
-- local extension = string.match(path, "[^.]+$")
local extension = util.getFileNameSuffix(path)
return Image.SUPPORTED_FORMATS[extension] and
Image.SUPPORTED_FORMATS[extension] or
false
end
return Image