Skip to content

Instantly share code, notes, and snippets.

@laurentperrinet
Last active December 23, 2020 09:03
Show Gist options
  • Save laurentperrinet/71d775bd51f1eee6869e1faf0098a7e5 to your computer and use it in GitHub Desktop.
Save laurentperrinet/71d775bd51f1eee6869e1faf0098a7e5 to your computer and use it in GitHub Desktop.
Import your iOS paper © 53 artwork to a folder of png files
"""
Import your iOS paper © 53 artwork to a folder of png files
Paper is an iOS application to create doodles, created by 53 and now owned by
weTransfer :
https://paper.bywetransfer.com/
This gist lives at:
https://gist.github.com/laurentperrinet/71d775bd51f1eee6869e1faf0098a7e5
"""
import datetime
from PIL import Image
import argparse
# construct the argument parse and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--input", default='2020_Luke_Paper', required=False)
ap.add_argument("-o", "--output", default='2020_Luke_Paper_export', required=False)
ap.add_argument("-v", "--verbose", action="store_true", default=True,
required=False, help="prints full ouput")
args = ap.parse_args()
if args.verbose: print (args)
# https://docs.python.org/3/library/pathlib.html
from pathlib import Path
path_input = Path(args.input)
path_output = Path(args.output)
path_output.mkdir(exist_ok=True)
import os, glob, json
for journal_name in path_input.iterdir(): # .glob('2016_D*'): #glob.glob(args.root + '/*'):
if journal_name.is_dir():
print(f'{journal_name=}')
# getting journal name
for fname in journal_name.glob('*.journal'):
with open(fname / Path('metadata.json')) as f:
data = json.load(f)
title = data['title']
if args.verbose: print(f'{title=}')
# generating output folder
journal_output = Path(args.output) / Path(title)
journal_output.mkdir(exist_ok=True)
# going through sketches
for sketch in journal_name.glob('*.page'):
if sketch.is_dir():
if args.verbose: print(f'{sketch=}')
with open(sketch / Path('metadata.json')) as f:
data = json.load(f)
if 'drawing' in data.keys():
if data['drawing']['hasSketch']:
# print(data, data['drawing']["hasSketch"])
sketch_name = sketch / Path('sketch')
output_image = Image.open(sketch_name)
if data['drawing']["hasFill"] :
background = Image.open(sketch / Path('fill'))
output_image = Image.alpha_composite(background, output_image)
ctime = str(datetime.datetime.fromtimestamp(sketch_name.stat().st_mtime))
ctime = ctime.replace(' ', '_').replace(':', '')
sketch_output = Path(journal_output) / Path(ctime + '.png')
white_bg = Image.new('RGBA', output_image.size, (255, 255, 255, 255))
output_image = Image.alpha_composite(white_bg, output_image)
output_image.putalpha(255)
output_image.save(sketch_output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment