Skip to content

Commit

Permalink
Add autosplit test
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Mar 17, 2019
1 parent 8c8d36b commit 5498da0
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions process
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def transform(config, root_folder):
):
if not os.path.exists(os.path.join(root_folder, path)):
os.makedirs(os.path.join(root_folder, path))
count = 0
for img in config['images']:
shutil.copyfile(os.path.join(root_folder, img), os.path.join(root_folder, 'process', os.path.basename(img)))
img = os.path.join(root_folder, 'process', os.path.basename(img))
Expand Down Expand Up @@ -151,6 +152,26 @@ def transform(config, root_folder):
print("Ignore image with no content: {}".format(img))
continue

try:
w, h = [int(e) for e in output(convert + [img, '-format', '%w %h', 'info:-']).strip().split(b' ')]
folder = os.path.join(root_folder, 'auto-split')
if not os.path.exists(folder):
os.makedirs(folder)

count += 1
call(convert + [
'-crop', '{}x{}+0+0'.format(w / 2, h),
img, os.path.join(folder, 'image-{}.png'.format(count))
])
count += 1
call(convert + [
'-crop', '{}x{}+{}+0'.format(w / 2, h, w / 2),
img, os.path.join(folder, 'image-{}.png'.format(count))
])

except Exception as e:
print('error: ' + e)

call([
'scantailor-cli', '--dpi=300', '--content-detection=normal',
'--output-dpi=300', '--color-mode=color_grayscale',
Expand Down

0 comments on commit 5498da0

Please sign in to comment.