-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomic_builder.lua
More file actions
executable file
·55 lines (43 loc) · 2.03 KB
/
comic_builder.lua
File metadata and controls
executable file
·55 lines (43 loc) · 2.03 KB
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
#!/usr/bin/env luajit
math.randomseed(os.time())
local version = "0.1.0"
package.path = (arg[0]:match("@?(.*/)") or arg[0]:match("@?(.*\\)")) .. "lib" .. package.config:sub(1, 1) .. "?.lua;" .. package.path
local utility = require "utility"
local argparse = utility.require("argparse")
utility.required_program("magick")
utility.required_program("pandoc")
local parser = argparse():description("Make an ebook of images from a folder full of sequentially named files."):help_max_width(80)
parser:argument("title", "Title of resultant ebook."):args(1)
parser:argument("author", "Author of resultant ebook."):args(1)
local options = parser:parse()
local lines = {
"---",
"title: " .. utility.escape_quotes_and_escapes(options.title):enquote(),
"author: [" .. utility.escape_quotes_and_escapes(options.author):enquote() .. "]",
"publisher: " .. ("comic_builder.lua/" .. version):enquote(),
"---",
"",
}
os.execute("mkdir raw_images")
os.execute("mkdir processed_images")
print("Press enter after images have been placed in 'raw_images'. ")
io.read("*line")
utility.ls("raw_images")(function(file_name)
local _, _, file_extension = utility.split_path_components(file_name)
local base_name = file_name:sub(1, -#file_extension-2)
if file_extension == "jpg" or file_extension == "jpeg" or file_extension == "png" then
local export_file_name = "processed_images/" .. base_name .. ".jpg"
if not utility.is_file(export_file_name) then
os.execute("magick " .. ("raw_images" .. utility.path_separator .. file_name):enquote() .. " -quality 50% " .. export_file_name:enquote())
lines[#lines + 1] = ""
end
elseif file_extension == "gif" then
os.execute("cp raw_images" .. utility.path_separator .. file_name .. " processed_images" .. utility.path_separator .. file_name)
lines[#lines + 1] = ""
end
end)
utility.open("text.md", "w", function(file)
file:write(table.concat(lines, "\n"))
file:write("\n")
end)
os.execute("pandoc text.md -o ebook.epub")