customidenticon-0.1.5/0000775000175000017500000000000013443516127014632 5ustar vladvlad00000000000000customidenticon-0.1.5/.version0000664000175000017500000000000513443516126016312 0ustar vladvlad000000000000000.1.5customidenticon-0.1.5/MANIFEST.in0000664000175000017500000000006013436550750016366 0ustar vladvlad00000000000000include runner README.md include runner .versioncustomidenticon-0.1.5/PKG-INFO0000664000175000017500000001034013443516127015725 0ustar vladvlad00000000000000Metadata-Version: 2.1 Name: customidenticon Version: 0.1.5 Summary: Python3 library for generate a variety of identicons Home-page: https://github.com/lexserest/customidenticon Author: LexSerest Author-email: lexserest@gmail.com Maintainer: LexSerest Maintainer-email: lexserest@gmail.com License: MIT Description: # CustomIdenticon ![image](https://user-images.githubusercontent.com/22620605/53684108-2c1c3180-3d1a-11e9-84ca-64547fb6ad51.png) Python library for generate a variety of identicons. [![image](https://travis-ci.org/LexSerest/customidenticon.svg?branch=master)](https://travis-ci.org/LexSerest/customidenticon) ## Features - 3 different types of identicons - change the final image size (size of elements, number of elements) - change border size - change background color - change the transparency of elements - change the output format (PNG, JPEG, etc.) - choice of hashing algorithm (including your own) ## Installation `pip install customidenticon` ## Usage End image size = size * block_size + border * 2 ```python import customidenticon identicon = customidenticon.create( "Test data", # Data type="pixels", # Type of algorithm (pixels, blocks or layers) format="png", # Output format salt="", # salt for more variants background="#f0f0f0", # background color block_visibility=140, # transparency of elements in the image (0-255) block_size=30, # size of elements (px) border=25, # border (px) size=5, # number of elements hash_func=None # hash function (auto) ) ``` ### Save ```python import customidenticon identicon = customidenticon.create("Test data", size=5) # identicon = b"\x89PNG\r\n\x1a\n\x00\x00\x00..." # save to file with open("identicon.png", "wb") as f: f.write(identicon) # to image import io from PIL import Image image = Image.open(io.BytesIO(identicon)) ``` ## Hash algorithm Use `hashlib` for change algorithm ```python import hashlib import customidenticon identicon = customidenticon.create("Test data", hash_func=hashlib.sha3_256) ``` Example custom hash algorithm ```python import customidenticon class MySuperHashAlgorithm: def __init__(self, *args): pass def hexdigest(self): return "0"*200 identicon = customidenticon.create("Test data", hash_func=MySuperHashAlgorithm) ``` ## Examples ```python import customidenticon # Create github-like (5x5) identicon1 = customidenticon.create("Test") # 200x200px (default for all) # or identicon1 = customidenticon.create("Test", type="pixels") # Create "pixels" type (6x6) # End image size 200x200px (6 * 25 + 25 * 2) identicon2 = customidenticon.create("Test", size=6, block_size=25) # Create "layers" type (3 layer) # End image size 200x200px (default size = 3 and block_size = 50) identicon4 = customidenticon.create("Test", type="layers") # Create "layers" type (8 layer) # End image size 200x200px (8 * 20 + 20 * 2) identicon5 = customidenticon.create("Test", type="layers", size=8, block_size=20, border=20) # Create "blocks" type (3x3) (200x200px) identicon6 = customidenticon.create("Test", type="block", block_visibility=100) ``` ##### Result ![image](https://user-images.githubusercontent.com/22620605/53685533-0c423900-3d2d-11e9-89e0-e3cc7bfa7548.png) Keywords: identicon image avatar profile github custom customidenticon Platform: UNKNOWN Description-Content-Type: text/markdown customidenticon-0.1.5/README.md0000664000175000017500000000573313443515764016127 0ustar vladvlad00000000000000# CustomIdenticon ![image](https://user-images.githubusercontent.com/22620605/53684108-2c1c3180-3d1a-11e9-84ca-64547fb6ad51.png) Python library for generate a variety of identicons. [![image](https://travis-ci.org/LexSerest/customidenticon.svg?branch=master)](https://travis-ci.org/LexSerest/customidenticon) ## Features - 3 different types of identicons - change the final image size (size of elements, number of elements) - change border size - change background color - change the transparency of elements - change the output format (PNG, JPEG, etc.) - choice of hashing algorithm (including your own) ## Installation `pip install customidenticon` ## Usage End image size = size * block_size + border * 2 ```python import customidenticon identicon = customidenticon.create( "Test data", # Data type="pixels", # Type of algorithm (pixels, blocks or layers) format="png", # Output format salt="", # salt for more variants background="#f0f0f0", # background color block_visibility=140, # transparency of elements in the image (0-255) block_size=30, # size of elements (px) border=25, # border (px) size=5, # number of elements hash_func=None # hash function (auto) ) ``` ### Save ```python import customidenticon identicon = customidenticon.create("Test data", size=5) # identicon = b"\x89PNG\r\n\x1a\n\x00\x00\x00..." # save to file with open("identicon.png", "wb") as f: f.write(identicon) # to image import io from PIL import Image image = Image.open(io.BytesIO(identicon)) ``` ## Hash algorithm Use `hashlib` for change algorithm ```python import hashlib import customidenticon identicon = customidenticon.create("Test data", hash_func=hashlib.sha3_256) ``` Example custom hash algorithm ```python import customidenticon class MySuperHashAlgorithm: def __init__(self, *args): pass def hexdigest(self): return "0"*200 identicon = customidenticon.create("Test data", hash_func=MySuperHashAlgorithm) ``` ## Examples ```python import customidenticon # Create github-like (5x5) identicon1 = customidenticon.create("Test") # 200x200px (default for all) # or identicon1 = customidenticon.create("Test", type="pixels") # Create "pixels" type (6x6) # End image size 200x200px (6 * 25 + 25 * 2) identicon2 = customidenticon.create("Test", size=6, block_size=25) # Create "layers" type (3 layer) # End image size 200x200px (default size = 3 and block_size = 50) identicon4 = customidenticon.create("Test", type="layers") # Create "layers" type (8 layer) # End image size 200x200px (8 * 20 + 20 * 2) identicon5 = customidenticon.create("Test", type="layers", size=8, block_size=20, border=20) # Create "blocks" type (3x3) (200x200px) identicon6 = customidenticon.create("Test", type="block", block_visibility=100) ``` ##### Result ![image](https://user-images.githubusercontent.com/22620605/53685533-0c423900-3d2d-11e9-89e0-e3cc7bfa7548.png) customidenticon-0.1.5/customidenticon/0000775000175000017500000000000013443516127020041 5ustar vladvlad00000000000000customidenticon-0.1.5/customidenticon/__init__.py0000664000175000017500000001530213436546650022161 0ustar vladvlad00000000000000import io from PIL import Image, ImageDraw import hashlib def _pixels(data, format="png", salt="", background="#f0f0f0", block_visibility=140, block_size=30, border=25, size=5, hash_func=None): """ Generating GitHub-like symmetrical identicons. End image size = size * block_size + border * 2 :param data: string :param format: output format (JPEG, PNG) :param block_size: size for one box (in pixels) :param border: size for border (in pixels) :param background: color for background. Format "#F4F4F4" or (244, 244, 244) :param salt: salt for a more varied result (only string) :param block_visibility: block transparency (in hex format. 255 - not transparent) :param size: number of blocks used :param hash_func: function to create a hash (hashlib.sha1, hashlib.sha256, hashlib.md5, etc) :return bytes """ if not hash_func: if size < 11: hash_func = hashlib.sha1 else: hash_func = hashlib.sha512 hashed = hash_func((str(data) + salt).encode("utf8")).hexdigest() color = "#" + hashed[:6] + hex(block_visibility)[2:] offset = size % 2 center = size // 2 + offset magic_int_all = 2 ** (size * center) magic_int = 2 ** size img_size = block_size * size + border * 2 hash_data = hashed[6:center * 8] if len(hash_data) < center * 8 - 6: raise Exception("Not enough hash size to generate. Please use another hash function or change size.") p = int(hash_data, 16) % magic_int_all img = Image.new("RGB", (img_size, img_size), color=background) draw = ImageDraw.Draw(img, "RGBA") to = range(center) for pos in to: data = bin((p >> (size * pos)) % magic_int)[2:].zfill(size) for index, visible in enumerate(data): if int(visible): x0 = block_size * pos + border y0 = block_size * index + border x1 = x0 + block_size - 1 y1 = y0 + block_size - 1 draw.rectangle([x0, y0, x1, y1], fill=color) if offset and (pos != to[-1]) or not offset: x0 = block_size * ((size - 1) - pos) + border x1 = x0 + block_size - 1 draw.rectangle([x0, y0, x1, y1], fill=color) byte = io.BytesIO() img.save(byte, format=format) return byte.getvalue() def _blocks(data, format="png", salt="", background="#f0f0f0", block_visibility=140, block_size=50, border=25, size=3, hash_func=None): """ Generating blocks of different colors. End image size = size * block_size + border * 2 :param data: string :param format: output format (JPEG, PNG) :param block_size: size for one box (in pixels) :param border: size for border (in pixels) :param background: color for background. Format "#F4F4F4" or (244, 244, 244) :param salt: salt for a more varied result (only string) :param block_visibility: block (in hex format. 255 - not transparent) :param size: number of blocks used :param hash_func: function to create a hash (hashlib.sha1, hashlib.sha256, hashlib.md5, etc) :return bytes """ if not hash_func: if size == 2: hash_func = hashlib.sha1 elif size == 3: hash_func = hashlib.sha256 else: hash_func = hashlib.sha512 hashed = hash_func((str(data) + salt).encode("utf8")).hexdigest() block_visibility = hex(block_visibility)[2:] img_size = size * block_size + border * 2 img = Image.new("RGB", (img_size, img_size), color=background) draw = ImageDraw.Draw(img, "RGBA") offset = 0 for x in range(size): for y in range(size): color = hashed[offset:offset + 6] + block_visibility if len(color) != 8: raise Exception("Not enough hash size to generate. Please use another hash function or change size.") offset += 6 x0 = x * block_size + border y0 = y * block_size + border x1 = x * block_size + block_size - 1 + border y1 = y * block_size + block_size - 1 + border draw.rectangle([x0, y0, x1, y1], fill="#" + color) byte = io.BytesIO() img.save(byte, format=format) return byte.getvalue() def _layers(data, format="png", salt="", background="#f0f0f0", block_visibility=140, block_size=50, border=25, size=3, hash_func=None): """ Generation of blocks of different colors located on each other. End image size = size * block_size + border * 2 :param data: string :param format: output format (JPEG, PNG) :param block_size: size for one box (in pixels) :param border: size for border (in pixels) :param background: color for background. Format "#F4F4F4" or (244, 244, 244) :param salt: salt for a more varied result (only string) :param block_visibility: block transparency (in hex format. 255 - not transparent) :param size: number of blocks used :param hash_func: function to create a hash (hashlib.sha1, hashlib.sha256, hashlib.md5, etc) :return bytes """ if not hash_func: if size == 2: hash_func = hashlib.sha1 elif size == 3: hash_func = hashlib.sha256 else: hash_func = hashlib.sha512 hashed = hash_func((str(data) + salt).encode("utf8")).hexdigest() block_visibility = hex(block_visibility)[2:] img_size = size * block_size + border * 2 img = Image.new("RGB", (img_size, img_size), color=background) draw = ImageDraw.Draw(img, "RGBA") block_size = block_size // 2 offset = 0 for x in range(size): color = hashed[offset:offset + 6] + block_visibility if len(color) != 8: raise Exception("Not enough hash size to generate. Please use another hash function or change size.") offset += 6 x0 = x * block_size + border y0 = x * block_size + border x1 = img_size - 1 - x * block_size - border y1 = img_size - 1 - x * block_size - border draw.rectangle([x0, y0, x1, y1], fill=background) draw.rectangle([x0, y0, x1, y1], fill="#" + color) byte = io.BytesIO() img.save(byte, format=format) return byte.getvalue() def create(data, type="pixels", **kwargs): funcs = { "pixels": _pixels, "blocks": _blocks, "layers": _layers, } if type not in funcs.keys(): raise Exception("Type does not exist") return funcs[type](data, **kwargs) customidenticon-0.1.5/customidenticon.egg-info/0000775000175000017500000000000013443516127021533 5ustar vladvlad00000000000000customidenticon-0.1.5/customidenticon.egg-info/PKG-INFO0000664000175000017500000001034013443516126022625 0ustar vladvlad00000000000000Metadata-Version: 2.1 Name: customidenticon Version: 0.1.5 Summary: Python3 library for generate a variety of identicons Home-page: https://github.com/lexserest/customidenticon Author: LexSerest Author-email: lexserest@gmail.com Maintainer: LexSerest Maintainer-email: lexserest@gmail.com License: MIT Description: # CustomIdenticon ![image](https://user-images.githubusercontent.com/22620605/53684108-2c1c3180-3d1a-11e9-84ca-64547fb6ad51.png) Python library for generate a variety of identicons. [![image](https://travis-ci.org/LexSerest/customidenticon.svg?branch=master)](https://travis-ci.org/LexSerest/customidenticon) ## Features - 3 different types of identicons - change the final image size (size of elements, number of elements) - change border size - change background color - change the transparency of elements - change the output format (PNG, JPEG, etc.) - choice of hashing algorithm (including your own) ## Installation `pip install customidenticon` ## Usage End image size = size * block_size + border * 2 ```python import customidenticon identicon = customidenticon.create( "Test data", # Data type="pixels", # Type of algorithm (pixels, blocks or layers) format="png", # Output format salt="", # salt for more variants background="#f0f0f0", # background color block_visibility=140, # transparency of elements in the image (0-255) block_size=30, # size of elements (px) border=25, # border (px) size=5, # number of elements hash_func=None # hash function (auto) ) ``` ### Save ```python import customidenticon identicon = customidenticon.create("Test data", size=5) # identicon = b"\x89PNG\r\n\x1a\n\x00\x00\x00..." # save to file with open("identicon.png", "wb") as f: f.write(identicon) # to image import io from PIL import Image image = Image.open(io.BytesIO(identicon)) ``` ## Hash algorithm Use `hashlib` for change algorithm ```python import hashlib import customidenticon identicon = customidenticon.create("Test data", hash_func=hashlib.sha3_256) ``` Example custom hash algorithm ```python import customidenticon class MySuperHashAlgorithm: def __init__(self, *args): pass def hexdigest(self): return "0"*200 identicon = customidenticon.create("Test data", hash_func=MySuperHashAlgorithm) ``` ## Examples ```python import customidenticon # Create github-like (5x5) identicon1 = customidenticon.create("Test") # 200x200px (default for all) # or identicon1 = customidenticon.create("Test", type="pixels") # Create "pixels" type (6x6) # End image size 200x200px (6 * 25 + 25 * 2) identicon2 = customidenticon.create("Test", size=6, block_size=25) # Create "layers" type (3 layer) # End image size 200x200px (default size = 3 and block_size = 50) identicon4 = customidenticon.create("Test", type="layers") # Create "layers" type (8 layer) # End image size 200x200px (8 * 20 + 20 * 2) identicon5 = customidenticon.create("Test", type="layers", size=8, block_size=20, border=20) # Create "blocks" type (3x3) (200x200px) identicon6 = customidenticon.create("Test", type="block", block_visibility=100) ``` ##### Result ![image](https://user-images.githubusercontent.com/22620605/53685533-0c423900-3d2d-11e9-89e0-e3cc7bfa7548.png) Keywords: identicon image avatar profile github custom customidenticon Platform: UNKNOWN Description-Content-Type: text/markdown customidenticon-0.1.5/customidenticon.egg-info/SOURCES.txt0000664000175000017500000000041713443516126023420 0ustar vladvlad00000000000000.version MANIFEST.in README.md setup.cfg setup.py customidenticon/__init__.py customidenticon.egg-info/PKG-INFO customidenticon.egg-info/SOURCES.txt customidenticon.egg-info/dependency_links.txt customidenticon.egg-info/requires.txt customidenticon.egg-info/top_level.txtcustomidenticon-0.1.5/customidenticon.egg-info/dependency_links.txt0000664000175000017500000000000113443516126025600 0ustar vladvlad00000000000000 customidenticon-0.1.5/customidenticon.egg-info/requires.txt0000664000175000017500000000000713443516126024127 0ustar vladvlad00000000000000pillow customidenticon-0.1.5/customidenticon.egg-info/top_level.txt0000664000175000017500000000002013443516126024254 0ustar vladvlad00000000000000customidenticon customidenticon-0.1.5/setup.cfg0000664000175000017500000000011713443516127016452 0ustar vladvlad00000000000000[metadata] description-file = README.md [egg_info] tag_build = tag_date = 0 customidenticon-0.1.5/setup.py0000664000175000017500000000221613436547703016353 0ustar vladvlad00000000000000import subprocess from setuptools import setup, find_packages from os.path import dirname, isdir, join PREFIX = "0.1.%s" with open(join(dirname(__file__), "README.md"), encoding="utf-8") as f: long_description = f.read() def get_version(): path = join(dirname(__file__), ".version") if isdir(".git"): version = PREFIX % int(subprocess.check_output(["git", "rev-list", "--all", "--count"])) with open(path, "w") as f: f.write(version) else: with open(path, "r") as f: version = f.read() return version setup( name="customidenticon", version=get_version(), description="Python3 library for generate a variety of identicons", long_description=long_description, long_description_content_type="text/markdown", keywords="identicon image avatar profile github custom customidenticon", author="LexSerest", author_email="lexserest@gmail.com", maintainer="LexSerest", maintainer_email="lexserest@gmail.com", url="https://github.com/lexserest/customidenticon", license="MIT", packages=find_packages(), install_requires=[ "pillow", ], )