(address)
| 9 | str_chan = '[chan]' |
| 10 | |
| 11 | def identiconize(address): |
| 12 | size = 48 |
| 13 | |
| 14 | # If you include another identicon library, please generate an |
| 15 | # example identicon with the following md5 hash: |
| 16 | # 3fd4bf901b9d4ea1394f0fb358725b28 |
| 17 | |
| 18 | try: |
| 19 | identicon_lib = BMConfigParser().get('bitmessagesettings', 'identiconlib') |
| 20 | except: |
| 21 | # default to qidenticon_two_x |
| 22 | identicon_lib = 'qidenticon_two_x' |
| 23 | |
| 24 | # As an 'identiconsuffix' you could put "@bitmessge.ch" or "@bm.addr" to make it compatible with other identicon generators. (Note however, that E-Mail programs might convert the BM-address to lowercase first.) |
| 25 | # It can be used as a pseudo-password to salt the generation of the identicons to decrease the risk |
| 26 | # of attacks where someone creates an address to mimic someone else's identicon. |
| 27 | identiconsuffix = BMConfigParser().get('bitmessagesettings', 'identiconsuffix') |
| 28 | |
| 29 | if not BMConfigParser().getboolean('bitmessagesettings', 'useidenticons'): |
| 30 | idcon = QtGui.QIcon() |
| 31 | return idcon |
| 32 | |
| 33 | if (identicon_lib[:len('qidenticon')] == 'qidenticon'): |
| 34 | # print identicon_lib |
| 35 | # originally by: |
| 36 | # :Author:Shin Adachi <shn@glucose.jp> |
| 37 | # Licesensed under FreeBSD License. |
| 38 | # stripped from PIL and uses QT instead (by sendiulo, same license) |
| 39 | import qidenticon |
| 40 | hash = hashlib.md5(addBMIfNotPresent(address)+identiconsuffix).hexdigest() |
| 41 | use_two_colors = (identicon_lib[:len('qidenticon_two')] == 'qidenticon_two') |
| 42 | opacity = int(not((identicon_lib == 'qidenticon_x') | (identicon_lib == 'qidenticon_two_x') | (identicon_lib == 'qidenticon_b') | (identicon_lib == 'qidenticon_two_b')))*255 |
| 43 | penwidth = 0 |
| 44 | image = qidenticon.render_identicon(int(hash, 16), size, use_two_colors, opacity, penwidth) |
| 45 | # filename = './images/identicons/'+hash+'.png' |
| 46 | # image.save(filename) |
| 47 | idcon = QtGui.QIcon() |
| 48 | idcon.addPixmap(image, QtGui.QIcon.Normal, QtGui.QIcon.Off) |
| 49 | return idcon |
| 50 | elif identicon_lib == 'pydenticon': |
| 51 | # print identicon_lib |
| 52 | # Here you could load pydenticon.py (just put it in the "src" folder of your Bitmessage source) |
| 53 | from pydenticon import Pydenticon |
| 54 | # It is not included in the source, because it is licensed under GPLv3 |
| 55 | # GPLv3 is a copyleft license that would influence our licensing |
| 56 | # Find the source here: http://boottunes.googlecode.com/svn-history/r302/trunk/src/pydenticon.py |
| 57 | # note that it requires PIL to be installed: http://www.pythonware.com/products/pil/ |
| 58 | idcon_render = Pydenticon(addBMIfNotPresent(address)+identiconsuffix, size*3) |
| 59 | rendering = idcon_render._render() |
| 60 | data = rendering.convert("RGBA").tostring("raw", "RGBA") |
| 61 | qim = QtGui.QImage(data, size, size, QtGui.QImage.Format_ARGB32) |
| 62 | pix = QtGui.QPixmap.fromImage(qim) |
| 63 | idcon = QtGui.QIcon() |
| 64 | idcon.addPixmap(pix, QtGui.QIcon.Normal, QtGui.QIcon.Off) |
| 65 | return idcon |
| 66 | |
| 67 | def avatarize(address): |
| 68 | """ |
no test coverage detected