Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:Python': 0.05; 'much!': 0.05; 'canvas': 0.07; 'pixel': 0.07; 'width': 0.07; 'subject:help': 0.07; 'modifies': 0.09; 'pixels': 0.09; 'portable': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr :python-list': 0.10; '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; 'monday,': 0.23; 'header': 0.24; 'cc:2**1': 0.24; 'cc:addr:python.org': 0.25; 'header:In- Reply-To:1': 0.25; 'header:User-Agent:1': 0.26; 'am,': 0.27; 'andrew': 0.27; 'lines': 0.28; 'received:209.85.212': 0.28; 'depth': 0.29; 'image,': 0.29; 'array': 0.29; 'convert': 0.29; "i'm": 0.29; 'stuff': 0.30; 'code': 0.31; 'file': 0.32; 'print': 0.32; 'that!': 0.33; 'code:': 0.33; "can't": 0.34; 'received:google.com': 0.34; 'text': 0.34; 'whatever': 0.35; 'received:209.85': 0.35; 'really': 0.36; 'but': 0.36; 'cc:no real name:2**1': 0.36; 'thank': 0.36; 'display': 0.36; 'october': 0.37; 'being': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'fact': 0.38; 'skip:" 10': 0.40; 'think': 0.40; 'your': 0.60; 'from:no real name:2**0': 0.60; 'map': 0.61; 'kind': 0.61; 'life,': 0.62; 'more': 0.63; 'actually,': 0.84; 'before...': 0.84; 'gray': 0.84; 'here!': 0.84; 'received:209.85.212.56': 0.91; 'picture': 0.96 Newsgroups: comp.lang.python Date: Tue, 30 Oct 2012 03:38:28 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=85.201.10.233; posting-account=vMlWXAoAAABorwHpel8u-aWzmlfyTQgA References: User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 85.201.10.233 MIME-Version: 1.0 Subject: Re: I need help installing pypng in Python 3.3 From: icgwh@tagyourself.com To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 105 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1351593517 news.xs4all.nl 6872 [2001:888:2000:d::a6]:53520 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:32480 On Monday, October 29, 2012 3:48:09 PM UTC+1, Andrew Robinson wrote: > On 10/29/2012 06:39 AM, icgwh@tagyourself.com wrote: >=20 > > That's very kind of you but I don't think it would be particularly fitt= ed to my needs. The program I'm trying to code creates an image as an 2D ar= ray 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 o= f rules, kind of like the game of life, only more complex. >=20 > > >=20 > > In fact I only need a library to "push" this array of pixels in a displ= ayable format for the GUI and in PNG format to write the image to disk. I d= on't need to do any fancy stuff with the image, just being able to display = and write it. >=20 > > >=20 > > >=20 > Then, actually, what I am suggesting was *almost* perfect. >=20 > To do transparency, you need to write the portable any map (PAM) formatio= n. >=20 >=20 >=20 > Simply print a text header to a file which says: >=20 >=20 >=20 > P7 >=20 > WIDTH 10 >=20 > HEIGHT 10 >=20 > DEPTH 4 >=20 > MAXVAL 255 >=20 > TUPLTYPE RGB_ALPHA >=20 > ENDHDR >=20 >=20 >=20 > And then dump your 2D array to that same file. >=20 > A very quick example in 17 lines of code: >=20 >=20 >=20 > io =3D open( "anyname.pam","w") >=20 > x,y =3D 10,10 >=20 > gray=3D(128,128,128,255) # R,G,B,A value >=20 > picture =3D [ [ gray ] * x ] * y # Make a blank gray canvas 2D array >=20 >=20 >=20 > # Do whatever you want to the 2D picture array here! >=20 >=20 >=20 > io.write( "P7\nWIDTH %d\nHEIGHT %d\nDEPTH 4\nMAXVAL 255\nTUPLTYPE=20 >=20 > RGB_ALPHA\nENDHDR\n" % (x,y) ) >=20 >=20 >=20 > for yi in xrange( y ): >=20 > for xi in xrange( x ): >=20 > pixel =3D picture[yi][xi] >=20 > io.write( chr(pixel[0]) ) # R value >=20 > io.write( chr(pixel[1]) ) # G value >=20 > io.write( chr(pixel[2]) ) # B value >=20 > io.write( chr(pixel[3]) ) # A value >=20 > io.flush() >=20 >=20 >=20 > io.close() >=20 >=20 >=20 > And that's it. You may of course make this more efficient -- I'm just=20 >=20 > showing it this way for clarity. >=20 > Many programs can read PAM directly; but for those that can't you can=20 >=20 > use nettools, or imagemagick, to convert it to PNG. That's really interesting! Thank you so much! Never heard of PAM before... = I will try that!