Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #59452

Re: Converting hex data to image

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <mail@timgolden.me.uk>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'url:pypi': 0.03; 'url:products': 0.07; 'pil': 0.09; 'suggest': 0.14; '......': 0.16; 'fetch': 0.16; 'from:addr:timgolden.me.uk': 0.16; 'from:name:tim golden': 0.16; 'hex': 0.16; 'message- id:@timgolden.me.uk': 0.16; 'received:74.55.86': 0.16; 'received:74.55.86.74': 0.16; 'received:smtp.webfaction.com': 0.16; 'received:webfaction.com': 0.16; 'skip:[ 40': 0.16; 'subject:Converting': 0.16; 'subject:image': 0.16; 'tjg': 0.16; 'wrote:': 0.18; 'implementing': 0.19; 'load': 0.23; 'header:User- Agent:1': 0.23; 'bytes': 0.24; 'received:192.168.100': 0.24; 'skip:{ 20': 0.24; 'header:In-Reply-To:1': 0.27; '[1]': 0.29; '[2]': 0.30; "skip:' 10": 0.31; 'url:python': 0.33; 'actual': 0.34; 'could': 0.34; 'convert': 0.35; 'there': 0.35; 'subject:data': 0.36; 'url:org': 0.36; 'server': 0.38; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'skip:* 10': 0.61; 'first': 0.61; 'save': 0.62; 'user,': 0.69; 'photo': 0.78; 'from:addr:mail': 0.83
Date Thu, 14 Nov 2013 16:18:38 +0000
From Tim Golden <mail@timgolden.me.uk>
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.0
MIME-Version 1.0
To python-list@python.org
Subject Re: Converting hex data to image
References <CALVX-oYZzX8CEvP58=mfyk2yYXFRkk4e0t66bFn8na-h_BNpHw@mail.gmail.com>
In-Reply-To <CALVX-oYZzX8CEvP58=mfyk2yYXFRkk4e0t66bFn8na-h_BNpHw@mail.gmail.com>
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2608.1384445921.18130.python-list@python.org> (permalink)
Lines 26
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1384445921 news.xs4all.nl 15993 [2001:888:2000:d::a6]:52255
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:59452

Show key headers only | View raw


On 14/11/2013 15:32, Shyam Parimal Katti wrote:
> I am implementing an authentication system(in Django) using LDAP as the
> backend(django-auth-ldap). When we fetch the data from the LDAP server
> for a particular valid user, the data associated with the user contains
> the thumbnail photo in hex representation. E.x.:
> 
> [('CN=XX,OU=Users,OU=Accounts,DC=test,DC=com',
> {'msExchBlockedSendersHash': ['\xce'], 'mailNickname': ['test_user'],
> 'primaryGroupID': ['513'], 'logonCount': ['1021'], *thumbnailPhoto:
> ['\xef\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\x01\x00`\x00`\x00\x00\xff\xdb\x00C\x00\x08\x06\x06\x07\x06\x05\x08\x07\x07\x07\t\t\x08\n\x0c\x14\r\x0c.....']*
> ...... ]
> 
> How do I convert the hex data for an image to the actual image?

Well, the first few bytes suggest that it's a JPEG, so save the bytes as
"something.jpg" and there you have it: an actual image.

Alternatively, you could load it into PIL [1] / Pillow [2] and
manipulate it as you see fit...

TJG

[1] http://www.pythonware.com/products/pil/
[2] https://pypi.python.org/pypi/Pillow/

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Converting hex data to image Tim Golden <mail@timgolden.me.uk> - 2013-11-14 16:18 +0000

csiph-web