Gitlab will be down on Friday 25th May (from 9:00 am to 12:00 )

...
 
Commits (5)
......@@ -18,11 +18,15 @@ texjson=$(trim:%.trim.jpg=%.tex.json)
lexsvg=$(trim:%.trim.jpg=%.lex.svg)
lexpng=$(trim:%.trim.jpg=%.lex.png)
lexjson=$(trim:%.trim.jpg=%.lex.json)
houghsvg=$(trim:%.trim.jpg=%.hough.svg)
houghpng=$(trim:%.trim.jpg=%.hough.png)
houghjson=$(trim:%.trim.jpg=%.hough.json)
snapshots=$(shell ls snapshots/*.pdf)
snapshotsjpg=$(snapshots:%.pdf=%.jpg)
dataimages=$(red) $(green) $(blue) $(gradientpng) $(contourspng) $(houghpng) $(lexpng) $(texpng)
alldata: $(contourssvg) $(contourspng) $(contoursjson) $(gradientsvg) $(gradientpng) $(gradientjson) $(red) $(redjson) $(green) $(greenjson) $(blue) $(bluejson) $(texsvg) $(texpng) $(texjson) $(lexsvg) $(lexpng) $(lexjson)
alldata: $(contourssvg) $(contourspng) $(contoursjson) $(gradientsvg) $(gradientpng) $(gradientjson) $(red) $(redjson) $(green) $(greenjson) $(blue) $(bluejson) $(texsvg) $(texpng) $(texjson) $(lexsvg) $(lexpng) $(lexjson) $(houghsvg) $(houghpng) $(houghjson)
snapshots: $(snapshotsjpg)
trim: $(trim)
......@@ -30,6 +34,7 @@ contours: $(contourspng) $(contourssvg) $(contoursjson)
gradients: $(gradientsvg) $(gradientpng) $(gradientjson)
channels: $(red) $(green) $(blue) $(redjson) $(greenjson) $(bluejson)
zapzeros:
find sample -size 0 -exec rm {} \;
cleandata:
......@@ -52,8 +57,8 @@ sample.csv: csv/mim.normalized.csv
sample.json: sample.csv scripts/csv2json.py
scripts/csv2json.py $< > $@
sample_with_data.json: sample.json $(contoursjson) $(gradientjson) $(redjson) $(greenjson) $(bluejson) $(texjson) $(lexjson)
scripts/joindata.py $^ > $@
sample_with_data.json: sample.json $(contoursjson) $(gradientjson) $(redjson) $(greenjson) $(bluejson) $(texjson) $(lexjson) $(houghjson)
scripts/joindata.py sample.json --inputglob "sample/*.json" > $@
# sample/exif.json:
# exiftool -FileModifyDate --json
......@@ -108,6 +113,17 @@ sample_with_data.json: sample.json $(contoursjson) $(gradientjson) $(redjson) $(
%.lex.png: %.lex.svg
inkscape --export-png=$@ $<
# hough
%.hough.svg: %.trim.jpg
bin/houghlines $< > $@
%.hough.json: %.hough.svg
scripts/svgcountpaths.py $< --json --id $*.jpg --key hough --img $*.hough.png --selector ".//{http://www.w3.org/2000/svg}line" > $@
%.hough.png: %.hough.svg
inkscape --export-png=$@ $<
%.jpg: %.pdf
convert $< $@
......@@ -119,26 +135,33 @@ sample_with_data.json: sample.json $(contoursjson) $(gradientjson) $(redjson) $(
# POSTER
#
poster.pdf: sample_with_data.json scripts/orderings.poster.py $(red) $(green) $(blue) $(gradientpng) $(contourspng)
poster.pdf: sample_with_data.json scripts/orderings.poster.py $(dataimages)
scripts/orderings.poster.py --filterzeros $< --output $@
poster2.pdf: sample_with_data.json scripts/orderings.poster.py $(red) $(green) $(blue) $(gradientpng) $(contourspng)
poster2.pdf: sample_with_data.json scripts/orderings.poster.py $(dataimages)
scripts/orderings.poster.py \
--pagesize A1 --landscape \
--columns 72 \
--fontsize 7 \
--filterzeros $< --output $@
poster3.pdf: sample_with_data.json scripts/orderings.poster.py $(red) $(green) $(blue) $(gradientpng) $(contourspng)
poster3.pdf: sample_with_data.json scripts/orderings.poster.py $(dataimages)
scripts/orderings.poster.py \
--pagesize A1 --landscape \
--columns 36 \
--fontsize 7 \
--filterzeros $< --output $@
poster4.pdf: sample_with_data.json scripts/orderings.poster.py $(red) $(green) $(blue) $(gradientpng) $(contourspng)
poster4.pdf: sample_with_data.json scripts/orderings.poster.py $(dataimages)
scripts/orderings.poster2.py \
--pagesize A1 --landscape \
--columns 101 \
--fontsize 7 \
--filterzeros $< --output $@
poster5.pdf: sample_with_data.json scripts/orderings.poster.columns.py $(dataimages)
scripts/orderings.poster.columns.py \
--pagesize A1 \
--columns 39 \
--fontsize 7 \
--filterzeros $< --output $@
#!/usr/bin/env python3
import argparse, json, sys
import argparse, json, sys, glob
ap = argparse.ArgumentParser("combine data.json and csv derived data")
ap.add_argument("src")
ap.add_argument("input", nargs="+")
ap.add_argument("input", nargs="*")
ap.add_argument("--inputglob", default=None, help="can take a glob")
args = ap.parse_args()
with open(args.src) as f:
......@@ -14,7 +15,12 @@ byid = {}
for i in base:
byid[i['id']] = i
for n in args.input:
if args.inputglob != None:
inputs = glob.glob(args.inputglob)
else:
inputs = args.input
for n in inputs:
print ("Reading data from {0}".format(n), file=sys.stderr)
with open(n) as f:
data = json.load(f)
......
#!/usr/bin/env python3
import os, sys, json, re
from math import floor
import datetime
from argparse import ArgumentParser
from PIL import Image
from reportlab.pdfgen.canvas import Canvas
import reportlab.lib.pagesizes
from reportlab.lib.units import inch, cm
from reportlab.pdfbase.ttfonts import TTFont, pdfmetrics
from reportlab.lib.utils import ImageReader
from reportlab.lib.colors import ghostwhite, grey, lightgrey
####
"""
support simple and expanded values
{ key: value }
key: {
value: 23,
label: '23'
}
"""
def value (x):
if type(x) == dict and 'value' in x:
return x['value']
return x
def non_zero_value (x):
val = x
if type(x) == dict and 'value' in x:
val = x['value']
if type(val) == list or type(val) == tuple:
return len([x for x in val if x]) > 0
else:
return val
def label (x):
if type(x) == dict and 'label' in x:
return x['label']
return x
ap = ArgumentParser("")
ap.add_argument("--filterzeros", default=False, action="store_true")
ap.add_argument("--pagesize", default="A1")
# ap.add_argument("--imagespath", default="/media/murtaugh/DIVERSIONSX/2016/DIVERSIONS/Diversies/Images/MIM_Instr_Africains")
ap.add_argument("--imagespath", default="sample")
ap.add_argument("--output", default="output.pdf")
ap.add_argument("--font", default="OSP-DIN.ttf")
ap.add_argument("--columns", type=int, default=39)
ap.add_argument("--fontsize", type=float, default=14.0)
ap.add_argument("--groupborder", type=float, default=1.5, help="vertical gap between groups")
ap.add_argument("--colspacing", type=float, default=1, help="horizontal gap between columns")
ap.add_argument("--cellborder", type=float, default=0.10)
ap.add_argument("--pageborder", type=float, default=2.5)
ap.add_argument("--pagetop", type=float, default=3.5)
ap.add_argument("--landscape", default=False, action="store_true")
ap.add_argument("--title", default="Thirteen Orderings - Collection of the MIM, MRAH Brussels, February 2018 - SICV")
ap.add_argument("data")
args = ap.parse_args()
pagesize = getattr(reportlab.lib.pagesizes, args.pagesize)
# DATA
with open (args.data) as f:
data = json.load(f)
## Sizing
pagemargin = {
'left': args.pageborder*cm,
'right': args.pageborder*cm,
'top': args.pagetop*cm,
'bottom': args.pageborder*cm
}
cellmargin = {
'left': args.cellborder*cm,
'right': args.cellborder*cm,
'top': args.cellborder*cm,
'bottom': args.cellborder*cm
}
groupborder = args.groupborder*cm
colspacing = args.colspacing*cm
totalcolspacing = (args.columns//2 - 1) * colspacing
if args.landscape:
pageheight, pagewidth = pagesize
else:
pagewidth, pageheight = pagesize
cols = args.columns
usablewidth = pagewidth - pagemargin['left'] - pagemargin['right'] - totalcolspacing
cellwidth = usablewidth / cols
cellheight = cellwidth
usableheight = pageheight - pagemargin['top'] - pagemargin['bottom'] - groupborder*2
rows = int(floor( usableheight / cellheight))
ccw = cellcontentswidth = cellwidth - cellmargin['left'] - cellmargin['right']
cch = cellcontentsheight = cellwidth - cellmargin['top'] - cellmargin['bottom']
# groupcols = int(floor(cols / 3.0))
grouprows = int(floor(rows / 3.0))
print ("Page size cols x rows: {0} x {1}".format(cols, rows), file=sys.stderr)
# FONTS
font = TTFont('LabelFont', args.font)
pdfmetrics.registerFont(font)
# PDF
canvas = Canvas(args.output, pagesize=(pagewidth, pageheight))
boxfill = 1,0,1
textcolor = 0,0,0
canvas.setStrokeColorRGB(0.0,0.0,0.0)
canvas.setFont('LabelFont', args.fontsize)
print ("{0} items".format(len(data)), file=sys.stderr)
def drawImageBox (ipath, x, y, c, r, boxsize=512, drawBorder=False, halign="center", valign="center"):
cx = x + (c*cellwidth)
cy = y + pageheight - pagemargin['top'] - ((r+1)*cellheight)
try:
im = Image.open(ipath)
# boxsize sets the resolution of the image such that it fits in boxsize x boxsize pixels
if boxsize != None:
im.thumbnail((boxsize, boxsize), Image.ANTIALIAS)
imw = (im.size[0]/boxsize) * ccw
imh = (im.size[1]/boxsize) * cch
else:
# fit the image in the box
imw = ccw
imh = im.size[1]
# centering dx,dy
if halign=="left":
dx = 0
elif halign=="center":
dx = (ccw - imw) / 2
else: # right
dx = (ccw-imw)
if valign=="top":
dy = (cch - imh)
elif valign=="center":
dy = (cch - imh) / 2
else: # "bottom"
dy = 0
# DRAW IMAGE
canvas.drawImage(
ImageReader(im),
cx+dx+cellmargin['left'],
cy+dy+cellmargin['bottom'],
width=imw,
height=imh,
mask='auto' # https://stackoverflow.com/questions/1308710/transparency-in-pngs-with-reportlab-2-3#1625350
)
if drawBorder:
canvas.rect(cx, cy, cellwidth, cellheight)
return cx, cy, dx, dy, imw, imh
except Exception as e:
print ("Exception {0}".format(e))
return cx, cy, 0, 0, cellwidth, cellheight
r = 0
c = 0
colstyle = "3groups"
canvas.setFillColorRGB(*textcolor)
# canvas.drawCentredString(cx+(cellwidth/2), cy+(cellheight/2), "{0}".format(txt))
cx = pagewidth/2
cy = pageheight - pagemargin['top'] + 2.0*cm
canvas.drawCentredString(cx, cy, "{0}".format(args.title))
groupx = pagemargin['left']
sortkeys = "name inventory image_filesize dimensions dating red green blue gradient contours hough tex lex".split()
for sortkey in sortkeys:
# SORT
if args.filterzeros:
sdata = [x for x in data if non_zero_value(x.get(sortkey))]
else:
sdata = data[:]
sdata.sort(key=lambda x: value(x[sortkey]))
print ("[{0}] range from {1} to {2}".format(sortkey, label(sdata[0][sortkey]), label(sdata[-1][sortkey])))
# split the data into 3 groups: min, middle, max
# each group has groupcols items
# midpoint = len(sdata)//2
# midstart = midpoint - (groupcols//2)
# groups = sdata[0:rows], sdata[-rows:]
if colstyle=="3groups":
midpoint = len(sdata)//2
midstart = midpoint - (grouprows//2)
groups = sdata[0:grouprows], sdata[midstart:midstart+grouprows], sdata[-grouprows:]
# Column label
cx = groupx + ((c+1)*cellwidth)
cy = pageheight - pagemargin['top']
canvas.setFillColorRGB(*textcolor)
# canvas.drawCentredString(cx+(cellwidth/2), cy+(cellheight/2), "{0}".format(txt))
canvas.drawCentredString(cx, cy+0.5*cm, "{0}".format(sortkey.upper()))
canvas.drawCentredString(cx, cy+0.25*cm, "({0} items)".format(len(sdata)))
groupy = 0 # pagemargin['bottom']
fillDataBox = False
for gi, group in enumerate(groups):
r = 0
for i in group:
ipath = i['img']
cx, cy, dx, dy, imw, imh = drawImageBox(ipath, groupx, groupy, c+1, r, halign="left")
if 'img' in i[sortkey]:
drawImageBox(i[sortkey]['img'], groupx, groupy, c, r, halign="right")
txt = label(i[sortkey])
if txt:
cx = groupx + (c*cellwidth)
cy = groupy + pageheight - pagemargin['top'] - ((r+1)*cellheight)
dx = (ccw-imw) # right align
dy = (cch-imh) / 2 #center
canvas.setStrokeColor(lightgrey)
canvas.setLineWidth(0.05)
canvas.rect(cx+dx+cellmargin['left'],cy+dy+cellmargin['bottom'],imw, imh)
canvas.setFillColorRGB(*textcolor)
# canvas.drawCentredString(cx+(cellwidth/2), cy+(cellheight/2), "{0}".format(txt))
canvas.drawCentredString(cx+dx+cellmargin['left']+(imw/2), cy+dy+cellmargin['bottom']+(imh/2), "{0}".format(txt))
r += 1
# groupx += groupborder + (cellwidth*groupcols)
groupy -= groupborder + (cellheight*grouprows)
groupx += colspacing
c += 2
canvas.showPage()
print("Saving to {0}".format(args.output), file=sys.stderr)
canvas.save()
......@@ -157,7 +157,7 @@ def drawImageBox (ipath, x, c, r, boxsize=100, drawBorder=False, valign="center"
return cx, cy, 0, 0, cellwidth, cellheight
r = 0
for sortkey in "name inventory image_filesize dimensions dating red green blue contours gradient tex lex".split():
for sortkey in "name inventory image_filesize dimensions dating red green blue gradient contours hough tex lex".split():
# SORT
if args.filterzeros:
sdata = [x for x in data if non_zero_value(x.get(sortkey))]
......