def read_gif(im): response = "" path = "/tmp/test.jpg" try: while 1: jpg = im.convert("RGB") jpg.save(path) img = Haishoku.loadHaishoku(path) code = get_code(img.dominant) response += str(code) # print(code); im.show(); time.sleep(1) im.seek(im.tell() + 1) except EOFError: pass return response
def display_haishoku(art_image, art_id): file = f"static/images/{art_image}" hai = Haishoku.loadHaishoku(file) palette = Haishoku.getPalette(file) # palette has two pieces of data, percent used in the color and RGB code for pal in palette: load_color_palette(pal[1]) color = Palette(c_percent=pal[0], c_palette=pal[1], artwork_id=art_id) db.session.add(color) db.session.commit() return color
def extract_user_palette(filename): """Display user image and color palette.""" def new_image(mode, size, color): return Image.new(mode, size, color) file = f"static/user_images/{filename}" hai = Haishoku.loadHaishoku(file) palette = Haishoku.getPalette(file) u_color_pal = [] for item in palette: c_pal = item[1] pal = new_image('RGB', (100, 100), c_pal) u_color_pal.append(c_pal) return render_template("user-palette.html", filename=filename, u_color_pal=u_color_pal)
def main(): path = "/Users/wujianming/Desktop/WechatIMG18547.jpeg" # path = "http://wx2.sinaimg.cn/large/89243dfbly1ffoekfainzj20dw05k0u7.jpg" # getPalette api palette = Haishoku.getPalette(path) # getDominant api dominant = Haishoku.getDominant(path) # showPalette api Haishoku.showPalette(path) # showDominant api # Haishoku.showDominant(path) # Haishoku object h = Haishoku.loadHaishoku(path) print(h.palette) print(h.dominant)
def main(): path = "demo_01.png" # getPalette api palette = Haishoku.getPalette(path) print(palette) # getDominant api dominant = Haishoku.getDominant(path) print(dominant) # showPalette api Haishoku.showPalette(path) # showDominant api Haishoku.showDominant(path) # Haishoku object h = Haishoku.loadHaishoku(path) print(h.image) print(h.palette) print(h.dominant)
def main(): url = "https://img3.doubanio.com/lpic/s27028282.jpg" r = requests.get(url) path = BytesIO(r.content) # getPalette api palette = Haishoku.getPalette(path) print(palette) # getDominant api dominant = Haishoku.getDominant(path) print(dominant) # showPalette api Haishoku.showPalette(path) # showDominant api Haishoku.showDominant(path) # Haishoku object h = Haishoku.loadHaishoku(path) print(h.palette) print(h.dominant)
def get_colorname(index, path): single_data = OrderedDict() try: haishoku = Haishoku.loadHaishoku(path) # Haishoku.showDominant(path) # single_data['图片路径名称'] = path palette = haishoku.palette main_color = palette[0][1] main_color_pct = palette[0][0] mian_colorname = min_color_diff(main_color, colors)[1] tmp_main_color = rgb2hex(main_color)[1:] # single_data['主要图片颜色'] = mian_colorname # single_data['主要图片颜色rgb'] = rgb2hex(main_color) # single_data['主要图片颜色占比'] = main_color_pct second_color = palette[1][1] second_color_pct = palette[1][0] second_colorname = min_color_diff(second_color, colors)[1] tmp_second_color = rgb2hex(second_color)[1:] # single_data['次要图片颜色'] = second_colorname # single_data['次要图片颜色rgb'] = rgb2hex(second_color) # single_data['次要图片颜色占比'] = second_color_pct thred_color = palette[2][1] thred_color_pct = palette[2][0] thred_colorname = min_color_diff(thred_color, colors)[1] tmp_thred_color = rgb2hex(thred_color)[1:] # single_data['次次要图片颜色'] = thred_colorname # single_data['次次要图片颜色rgb'] = rgb2hex(thred_color) # single_data['次次要图片颜色占比'] = thred_color_pct row_line = [ path, mian_colorname, "#" + tmp_main_color, main_color_pct, second_colorname, "#" + tmp_second_color, second_color_pct, thred_colorname, "#" + tmp_thred_color, thred_color_pct ] my_sheet.append(row_line) my_sheet["B" + str(2 + int(index))].fill = PatternFill( fill_type=fills.FILL_SOLID, fgColor=rgb2hex( list(colors.keys())[list( colors.values()).index(mian_colorname)])[1:], bgColor=tmp_main_color) my_sheet["C" + str(2 + int(index))].fill = PatternFill( fill_type=fills.FILL_SOLID, fgColor=tmp_main_color, bgColor=tmp_main_color) my_sheet["E" + str(2 + int(index))].fill = PatternFill( fill_type=fills.FILL_SOLID, fgColor=rgb2hex( list(colors.keys())[list( colors.values()).index(second_colorname)])[1:], bgColor=tmp_main_color) my_sheet["F" + str(2 + int(index))].fill = PatternFill( fill_type=fills.FILL_SOLID, fgColor=tmp_second_color, bgColor=tmp_second_color) my_sheet["H" + str(2 + int(index))].fill = PatternFill( fill_type=fills.FILL_SOLID, fgColor=rgb2hex( list(colors.keys())[list( colors.values()).index(thred_colorname)])[1:], bgColor=tmp_main_color) my_sheet["I" + str(2 + int(index))].fill = PatternFill( fill_type=fills.FILL_SOLID, fgColor=tmp_thred_color, bgColor=tmp_thred_color) print(index + 1) # print(path,'主要颜色是:'+mian_colorname,'主要颜色占比:'+str(main_color_pct*100)+'%',' 次要颜色是:'+second_colorname,'次要颜色占比:'+str(second_color_pct*100)+'%',' 次次要颜色是:'+thred_colorname,'次次要颜色占比:'+str(thred_color_pct*100)+'%') except Exception as e: print('错误-->', path, e)
from haishoku.haishoku import Haishoku import sys def convert_to_hex(rgba): return "#" + ('%02x%02x%02x%02x' % rgba) haishoku = Haishoku.loadHaishoku(str(sys.argv[1])) palette = [] for color in haishoku.palette: hex_color = convert_to_hex((color[1][0], color[1][1], color[1][2], 255)) palette += hex_color print(hex_color)
from haishoku.haishoku import Haishoku from PIL import Image import pprint img_path = 'images/kershisnik.jpg' haishoku = Haishoku.loadHaishoku(img_path) Haishoku.showPalette(img_path) palette = Haishoku.getPalette(img_path) print('palette: {}'.format(palette))
import os import csv sys.path.insert(0, "..") from haishoku.haishoku import Haishoku folder = "/Users/talamram/Downloads/thike/" # Count files in selected repository counter = 0 for file in os.listdir('..'): counter += 1 print(str(counter) + 'files counted!') # Iterate through images in folder and extract dominant colour and palette # and write them to a csv path = "test.JPG" # getPalette api palette = Haishoku.getPalette(path) # getDominant api dominant = Haishoku.getDominant(path) # Haishoku object h = Haishoku.loadHaishoku(path) print('= showpalette =') print(h.palette) print('= dominant =') print(h.dominant)
rl.SetTargetFPS(30) def get_dropped_files(): files = [] if rl.IsFileDropped(): file_count = ffi.new('int *') files = rl.GetDroppedFiles(file_count) files = [ffi.string(files[i]).decode() for i in range(file_count[0])] rl.ClearDroppedFiles() return files while not rl.WindowShouldClose(): for file in get_dropped_files(): h = Haishoku.loadHaishoku(file) colors = {str(blob): blob[1] for blob in h.palette} rl.BeginDrawing() rl.ClearBackground(WHITE) x, y = 0, 0 for name, color in colors.items(): r, g, b = color rl.DrawRectangle(x, y, TILE_SIZE, TILE_SIZE, (r, g, b, 255)) x += TILE_SIZE if x > WIDTH: x = 0 y += TILE_SIZE rl.EndDrawing()