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

...
 
Commits (2)
......@@ -12,10 +12,18 @@ green=$(trim:%.trim.jpg=%.green.png)
greenjson=$(trim:%.trim.jpg=%.green.json)
blue=$(trim:%.trim.jpg=%.blue.png)
bluejson=$(trim:%.trim.jpg=%.blue.json)
texsvg=$(trim:%.trim.jpg=%.tex.svg)
texpng=$(trim:%.trim.jpg=%.tex.png)
texjson=$(trim:%.trim.jpg=%.tex.json)
lexsvg=$(trim:%.trim.jpg=%.lex.svg)
lexpng=$(trim:%.trim.jpg=%.lex.png)
lexjson=$(trim:%.trim.jpg=%.lex.json)
snapshots=$(shell ls snapshots/*.pdf)
snapshotsjpg=$(snapshots:%.pdf=%.jpg)
alldata: $(contourssvg) $(contourspng) $(contoursjson) $(gradientsvg) $(gradientpng) $(gradientjson) $(red) $(redjson) $(green) $(greenjson) $(blue) $(bluejson) $(texsvg) $(texpng) $(texjson) $(lexsvg) $(lexpng) $(lexjson)
snapshots: $(snapshotsjpg)
trim: $(trim)
contours: $(contourspng) $(contourssvg) $(contoursjson)
......@@ -35,7 +43,8 @@ cleangradientpng:
# sample.csv: csv/export_mim.csv
sample.csv: csv/mim.normalized.csv
# head -n 101 $< > $@
scripts/csvrandom.py --shuffle --limit 100 --copyimages --outputpath sample $< $@
# scripts/csvrandom.py --shuffle --limit 100 --copyimages --outputpath sample $< $@
scripts/csvrandom.py --copyimages --outputpath sample $< $@
%.trim.jpg: %.orig.jpg
convert $< -gravity South -crop 0x0+0+25 $@
......@@ -43,7 +52,7 @@ 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)
sample_with_data.json: sample.json $(contoursjson) $(gradientjson) $(redjson) $(greenjson) $(bluejson) $(texjson) $(lexjson)
scripts/joindata.py $^ > $@
# sample/exif.json:
......@@ -84,10 +93,27 @@ sample_with_data.json: sample.json $(contoursjson) $(gradientjson) $(redjson) $(
%.blue.json: %.blue.png
convert $< -format %c histogram:info:- | scripts/histcount.py --json --id $*.jpg --key blue --img $*.blue.png > $@
# texture + lex
%.tex.svg %.lex.svg: %.trim.jpg
bin/texture $< $*.tex.svg $*.lex.svg /dev/null /dev/null /dev/null
%.tex.json: %.tex.svg
scripts/svgcountpaths.py $< --json --id $*.jpg --key tex --img $*.tex.png --selector ".//{http://www.w3.org/2000/svg}g[@class='symbol']" > $@
%.lex.json: %.lex.svg
scripts/svgcountpaths.py $< --json --id $*.jpg --key lex --img $*.tex.png --selector ".//{http://www.w3.org/2000/svg}g[@class='word']" > $@
%.tex.png: %.tex.svg
inkscape --export-png=$@ $<
%.lex.png: %.lex.svg
inkscape --export-png=$@ $<
%.jpg: %.pdf
convert $< $@
%.tiles.pdf: %.pdf
pdfposter -m A4 -p A1 $< $@
#
# POSTER
......@@ -110,9 +136,6 @@ poster3.pdf: sample_with_data.json scripts/orderings.poster.py $(red) $(green) $
--fontsize 7 \
--filterzeros $< --output $@
poster3.tiles.pdf: poster3.pdf
pdfposter -m A4 -p A1 $< $@
poster4.pdf: sample_with_data.json scripts/orderings.poster.py $(red) $(green) $(blue) $(gradientpng) $(contourspng)
scripts/orderings.poster2.py \
--pagesize A1 --landscape \
......
......@@ -9,7 +9,7 @@ ap = argparse.ArgumentParser("Copy ROWs of Csv and images")
ap.add_argument("src")
ap.add_argument("output")
ap.add_argument("--shuffle", default=False, action="store_true")
ap.add_argument("--limit", type=int, default=100)
ap.add_argument("--limit", type=int, default=None)
ap.add_argument("--copyimages", default=False, action="store_true")
ap.add_argument("--filterimageswithsize", type=int, default=9134, help="used to remove placeholder images")
ap.add_argument("--inputpath", default="/media/murtaugh/DIVERSIONSX/2016/DIVERSIONS/scrape/mim/")
......@@ -46,3 +46,4 @@ with open(args.output, "w") as f:
count += 1
if args.limit != None and count>=args.limit:
break
print ("Copied {0} rows".format(count), file=sys.stderr)
\ No newline at end of file
......@@ -162,10 +162,10 @@ def drawImageBox (ipath, x, c, r, boxsize=100, drawBorder=False, valign="center"
return cx, cy, dx, dy, imw, imh
r = 0
for sortkey in "name inventory image_filesize dimensions dating red green blue contours gradient".split():
for sortkey in "name inventory image_filesize dimensions dating red green blue contours gradient tex lex".split():
# SORT
if args.filterzeros:
sdata = [x for x in data if non_zero_value(x[sortkey])]
sdata = [x for x in data if non_zero_value(x.get(sortkey))]
else:
sdata = data[:]
sdata.sort(key=lambda x: value(x[sortkey]))
......
#!/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=101)
ap.add_argument("--fontsize", type=float, default=14.0)
ap.add_argument("--groupborder", type=float, default=0, help="horizontal gap between groups")
ap.add_argument("--cellborder", type=float, default=0.10)
ap.add_argument("--pageborder", type=float, default=2.5)
ap.add_argument("--landscape", default=False, action="store_true")
ap.add_argument("data")
args = ap.parse_args()
pagesize = getattr(reportlab.lib.pagesizes, args.pagesize)
# # datetime
# # parsed_date = datetime.datetime.strptime( mydate, "%Y:%m:%d %H:%M:%S" )
# def parsedate (d):
# # 2010:11:25 17:33:12+01:00
# # map +01:00 to +0100 which strptime can grok as %z
# d = re.sub(r"\+(\d\d):(\d\d)$", r"+\1\2", d)
# return datetime.datetime.strptime(d, "%Y:%m:%d %H:%M:%S%z")
# DATA
with open (args.data) as f:
data = json.load(f)
## Sizing
pagemargin = {
'left': args.pageborder*cm,
'right': args.pageborder*cm,
'top': args.pageborder*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
if args.landscape:
pageheight, pagewidth = pagesize
else:
pagewidth, pageheight = pagesize
cols = args.columns
usablewidth = pagewidth - pagemargin['left'] - pagemargin['right'] - 2*groupborder
cellwidth = usablewidth / cols
cellheight = cellwidth
rows = int(floor( (pageheight - pagemargin['top'] - pagemargin['bottom']) / cellheight))
ccw = cellcontentswidth = cellwidth - cellmargin['left'] - cellmargin['right']
cch = cellcontentsheight = cellwidth - cellmargin['top'] - cellmargin['bottom']
groupcols = int(floor(cols / 3.0))
# 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, c, r, boxsize=100, drawBorder=False, valign="center"):
im = Image.open(ipath)
# boxsize sets the resolution of the image such that it fits in boxsize x boxsize pixels
im.thumbnail((boxsize, boxsize), Image.ANTIALIAS)
imw = (im.size[0]/boxsize) * ccw
imh = (im.size[1]/boxsize) * cch
# centering dx,dy
if valign=="top":
dx, dy = (ccw - imw) / 2, (cch - imh)
elif valign=="center":
dx, dy = (ccw - imw) / 2, (cch - imh) / 2
else: # "bottom"
dx, dy = (ccw - imw) / 2, 0
cx = x + (c*cellwidth)
cy = pageheight - pagemargin['top'] - ((r+1)*cellheight)
# 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
orderings = []
for sortkey in "name inventory image_filesize dimensions dating red green blue contours gradient tex lex".split():
# SORT
if args.filterzeros:
sdata = [x for x in data if non_zero_value(x[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])))
orderings.append((sortkey, sdata))
from random import choice
# pick random item from first list
item = choice(orderings[0][1])
for sortkey, sdata in orderings:
try:
index = sdata.index(item)
print ("item is {0}/{1} in {2}".format(index, len(sdata), sortkey))
except ValueError:
print ("item is not in {0}/{1}".format(sortkey, len(sdata)))
midcol = int(floor(cols/2))
print ("midcol {0}".format(midcol), file=sys.stderr)
r = 0
for sortkey, sdata in orderings:
groupx = pagemargin['left']
try:
index = sdata.index(item)
print ("item is {0}/{1} in {2}".format(index, len(sdata), sortkey))
c = midcol - index
for i in sdata:
if c>=0 and c<cols:
ipath = i['img']
cx, cy, dx, dy, imw, imh = drawImageBox(ipath, groupx, c, r+1, valign="top")
if 'img' in i[sortkey]:
drawImageBox(i[sortkey]['img'], groupx, c, r, valign="bottom")
txt = label(i[sortkey])
if txt:
cx = groupx + (c*cellwidth)
cy = pageheight - pagemargin['top'] - ((r+1)*cellheight)
canvas.setStrokeColor(lightgrey)
canvas.setLineWidth(0.05)
canvas.rect(cx+dx+cellmargin['left'],cy+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+cellmargin['bottom']+(imh/2), "{0}".format(txt))
c += 1
except ValueError:
print ("item is not in {0}/{1}".format(sortkey, len(sdata)))
r += 2
canvas.showPage()
print("Saving to {0}".format(args.output), file=sys.stderr)
canvas.save()