summaryrefslogtreecommitdiff
path: root/pictures.py
blob: dc93119cfd4b98b667368d4fd9c563dcf3fbed79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python3

import os
import numpy as np
import subprocess
import json


def descriptors(file):
    npy = os.path.join(
        os.path.dirname(file),
        ".meta",
        "descriptors",
        os.path.basename(os.path.splitext(file)[0]) + ".npy",  # TODO
    )
    return np.load(npy, allow_pickle=False)


mail = "pdp8@pdp8.info"
cmd = "grep '3$' /home/ch/img/art/.meta/ratings|cut -f1"
favs = subprocess.check_output(cmd, shell=True, text=True).splitlines()
distances = {}
for fav in favs:
    basename = os.path.basename(fav)
    # out = os.path.join("/home/ch/pub/pictures/", basename)
    out = os.path.join("/srv/www/pdp8-test/pictures/", basename)
    cmd = "convert '" + fav + "' -strip -resize 1024x '" + out + "'"
    os.system(cmd)
    cmd = (
        "exiv2 -M'set Xmp.dc.creator "
        + mail
        + "' -M'set Xmp.dc.rights © "
        + mail
        + "' -M'set Xmp.dc.license http://creativecommons.org/licenses/by-sa/4.0/' -M'set Xmp.xmpRights.UsageTerms Creative Commons Attribution-ShareAlike 4.0 International License' -M'set Xmp.xmpRights.Marked True' -M'set Xmp.dc.description Original artwork available from "
        + mail
        + "' "
        + out
    )
    os.system(cmd)
    """
    fav_d = descriptors(fav)
    distances[basename] = {}
    for img in favs:
        if fav != img:
            img_d = descriptors(img)
            sim = np.dot(fav_d, img_d) / (np.linalg.norm(fav_d) * np.linalg.norm(img_d))
            img_basename = os.path.basename(img)
            distances[basename][img_basename] = np.float64(1.0 - sim)
with open("/home/ch/pub/distances.js", "w") as f:
    s = "distances = " + json.dumps(distances)
    print(s, file=f)
    """