Skip to content

Commit d231870

Browse files
committed
Image processing with ImageMagick
1 parent e0f610f commit d231870

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

tools/Images.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#! py -3
2+
"""
3+
build images for ebook
4+
"""
5+
TODO = """
6+
"""
7+
from pathlib import Path
8+
import pprint
9+
import os, sys, re, shutil
10+
from itertools import chain
11+
from betools import CmdLine, visitDir, ruler, head
12+
13+
resources = Path(r'C:\Users\Bruce\Dropbox\___OnJava\resources')
14+
src = resources/ "Images-svg"
15+
target = resources / "Images"
16+
17+
@CmdLine('x')
18+
def clean_and_setup():
19+
"""Delete old directory, create and populate new one"""
20+
os.chdir(str(resources))
21+
if target.exists():
22+
assert target.is_dir(), "Images must be a directory"
23+
shutil.rmtree(str(target))
24+
target.mkdir()
25+
for img in src.glob("*.svg"):
26+
print(img.name)
27+
shutil.copy(str(img), str(target))
28+
29+
# convert_command = "convert {} -resize 1200 {}"
30+
convert_command = "convert {} {}"
31+
32+
@CmdLine('c')
33+
def convert():
34+
"""Convert to desired format"""
35+
os.chdir(str(target))
36+
for img in Path(".").glob("*.svg"):
37+
cmd = convert_command.format(img, img.with_suffix(".gif"))
38+
print(cmd)
39+
os.system(cmd)
40+
41+
42+
43+
if __name__ == '__main__': CmdLine.run()
44+

tools/backup.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ tools = [
5050
"AttachResults.py",
5151
"update_git.py",
5252
"ProcessEbook.py",
53+
"Images.py",
5354
"backup.bat",
5455
"go.bat",
5556
Path(".") / "ebook_resources" / "onjava.css",

0 commit comments

Comments
 (0)