diff --git a/image_list.py b/image_list.py index 8a18cdf..7ad0eb23 100755 --- a/image_list.py +++ b/image_list.py @@ -238,8 +238,10 @@ def append_colors(sqlfile): conn.commit() return -def find_color_nearest(sqlfile,src): - conn=sqlite3.connect(sqlfile) +def find_color_nearest(opts): + """ Find closest matching images to given RGB color """ + src=opts.nearestcolor + conn=sqlite3.connect(opts.sqlfile) conn.text_factory=str db=conn.cursor() src=[float(i) for i in src.strip().strip('"').split(',')] @@ -247,9 +249,20 @@ def find_color_nearest(sqlfile,src): src.append(1) db.execute("SELECT file, ABS(BR-?)+ABS(BG-?)+ABS(BB-?) as K,BR,BG,BB FROM list ORDER BY K LIMIT ?", (src[0],src[1],src[2],src[3])) + hits=[] for hit in db: - print "%(f)s : D %(d).2f (RGB %(r).2f,%(g).2f,%(b).2f)" % {'f':hit[0],'d':hit[1], - 'r':hit[2],'g':hit[3], 'b':hit[4]} + hits.append(hit) + + file_len=str(max([len(x[0]) for x in hits])) + for c in range(len(hits)): + print( ('{: <'+file_len+'} D {:.2f} (RGB {:.2f},{:.2f},{:.2f})').format(hits[c][0], + hits[c][1], + hits[c][2], + hits[c][3], + hits[c][4])) + if opts.viewer: + fnames=[x[0] for x in hits] + subprocess.call(opts.viewer.replace('%f', " ".join(fnames)), shell=True) return def get_colors(filename): @@ -580,7 +593,7 @@ def main(): print('Random lists...') random_lists(options.sqlfile) if options.nearestcolor: - find_color_nearest(options.sqlfile,options.nearestcolor) + find_color_nearest(options) if options.similarity!=None: if os.path.exists(options.similarity): find_fingerprint_nearest(options)