Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: 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; 'subject:Python': 0.05; 'canvas': 0.07; 'pixel': 0.07; 'width': 0.07; 'subject:help': 0.07; 'modifies': 0.09; 'pixels': 0.09; 'portable': 0.09; 'gui': 0.11; 'library': 0.15; 'component': 0.15; 'value.': 0.15; '*almost*': 0.16; '255': 0.16; 'disk.': 0.16; 'dump': 0.16; 'fancy': 0.16; 'perfect.': 0.16; 'png': 0.16; 'subject:3.3': 0.16; 'suggesting': 0.16; 'wrote:': 0.17; 'subject:need': 0.17; 'creates': 0.18; 'file.': 0.20; 'trying': 0.21; 'defined': 0.22; 'example': 0.23; 'header': 0.24; 'header:In-Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'am,': 0.27; 'lines': 0.28; 'depth': 0.29; 'image,': 0.29; 'received:72.167.82': 0.29; 'array': 0.29; 'convert': 0.29; "i'm": 0.29; 'stuff': 0.30; 'code': 0.31; 'file': 0.32; 'print': 0.32; 'to:addr:python-list': 0.33; 'code:': 0.33; "can't": 0.34; 'text': 0.34; 'whatever': 0.35; 'but': 0.36; 'display': 0.36; 'being': 0.37; 'subject:: ': 0.38; 'fact': 0.38; 'to:addr:python.org': 0.39; 'skip:" 10': 0.40; 'think': 0.40; 'your': 0.60; 'map': 0.61; 'received:network': 0.61; 'kind': 0.61; 'life,': 0.62; 'received:phx3.secureserver.net': 0.62; 'received:prod.phx3.secureserver.net': 0.62; 'received:unknown': 0.63; 'more': 0.63; 'header:Reply-To:1': 0.68; 'reply-to:no real name:2**0': 0.72; 'actually,': 0.84; 'gray': 0.84; 'here!': 0.84; 'picture': 0.96 Date: Mon, 29 Oct 2012 07:48:09 -0700 From: Andrew Robinson User-Agent: Mozilla/5.0 (X11; Linux i686; rv:8.0) Gecko/20111126 Thunderbird/8.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: I need help installing pypng in Python 3.3 References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: andrew3@r3dsolutions.com List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 48 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1351547648 news.xs4all.nl 6919 [2001:888:2000:d::a6]:49696 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:32424 On 10/29/2012 06:39 AM, icgwh@tagyourself.com wrote: > That's very kind of you but I don't think it would be particularly fitted to my needs. The program I'm trying to code creates an image as an 2D array of "pixels" which is defined by RGBA value. My program needs to access and modifies every component of every pixels in the image following a set of rules, kind of like the game of life, only more complex. > > In fact I only need a library to "push" this array of pixels in a displayable format for the GUI and in PNG format to write the image to disk. I don't need to do any fancy stuff with the image, just being able to display and write it. > > Then, actually, what I am suggesting was *almost* perfect. To do transparency, you need to write the portable any map (PAM) formation. Simply print a text header to a file which says: P7 WIDTH 10 HEIGHT 10 DEPTH 4 MAXVAL 255 TUPLTYPE RGB_ALPHA ENDHDR And then dump your 2D array to that same file. A very quick example in 17 lines of code: io = open( "anyname.pam","w") x,y = 10,10 gray=(128,128,128,255) # R,G,B,A value picture = [ [ gray ] * x ] * y # Make a blank gray canvas 2D array # Do whatever you want to the 2D picture array here! io.write( "P7\nWIDTH %d\nHEIGHT %d\nDEPTH 4\nMAXVAL 255\nTUPLTYPE RGB_ALPHA\nENDHDR\n" % (x,y) ) for yi in xrange( y ): for xi in xrange( x ): pixel = picture[yi][xi] io.write( chr(pixel[0]) ) # R value io.write( chr(pixel[1]) ) # G value io.write( chr(pixel[2]) ) # B value io.write( chr(pixel[3]) ) # A value io.flush() io.close() And that's it. You may of course make this more efficient -- I'm just showing it this way for clarity. Many programs can read PAM directly; but for those that can't you can use nettools, or imagemagick, to convert it to PNG.