Advertisement
here2share

# s60_base64_to_png.py

Jun 7th, 2016
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # s60_base64_to_png.py
  2.  
  3. from cStringIO import StringIO # ZZZ
  4. import appuifw, e32, graphics
  5. from graphics import Image
  6. import base64, os
  7. import tempfile
  8.  
  9.  
  10. def draw(rect):
  11.     try: canvas.blit(img)
  12.     except: pass
  13.  
  14. canvas = appuifw.Canvas(redraw_callback=draw)
  15. appuifw.app.directional_pad=False
  16. appuifw.app.orientation='portrait'
  17. appuifw.app.screen='large'
  18. appuifw.app.body=canvas
  19. w,h = canvas.size
  20. img=graphics.Image.new((w,h))
  21.  
  22. py_png_b64='''\
  23. R0lGODlhQABAAPcAAAAAAAAPMwAXNwAaOAAYQwAbQQAdQQAbTwAeSwAWUQMmQgAjSwEnSwYuTwoo
  24. SggtSAwrSAAlVAAgWQAmWAAqVgAuVwAuXQcuWAw1TQs5Xhk0SQAsYwAxZAA1YQA0bAA6bAA/dyw/
  25. UAxAbgxGeh5BYRxHbRRKdBRNfi5IXC5OaCJQdCNUfzdTajlQYj1UaTJWdDZge0BXaUZZaE1dakJa
  26. cEBffElhc0lieUlmfU9leQZJgBRVjB5bjypehzNXhzFbgTlchiZjljhkhzRplixtozNwozF1qzp4
  27. q0BehERmhENli0dshUZvjktylk1wkE92kltvgVBwiVp1g1lyiVl1il95j1B3l1V3klh6lmB2iWt7
  28. lUWDuUaIvEqCskmGul6Col2FqVSLtVONvVqMtl+NsWaInmmAlGyGnHOGlHGHmXGKnnqJk3mMm3uR
  29. lX2Qn2SGpmqIoW+Pp2yOrGeRuXGLoneOoHaPo3STp3eSrXyRonWZuX2gvmOWwW2aw2meynOfwnGh
  30. yXuhw3yly3iqz3ypz3Sl0HCp1pt+Ha6ED6SAE6yDGqeRF7OEBbqTCriTFr6fEKyJLaODMKWWJqWS
  31. M7WTI7aWN62iJrqlKrekOJiOR5uRTKSTRqaXVa2bV7mZR7mdVKmeZ62da62ec7Cfd7ujRrCmXrGt
  32. W7yoWq6jaqyicbWga7OpbbqpbbSrebmueMGXC8SaFcSZJcOcNcqjGtSoHc2pJ8yrOcG1P9iuKdG4
  33. LdC5PtmwPNq5MN29PcurScqtWtG8S9uwS9G8X921Xsmvbc2yd9C9cN/AUNHAfeHKRePMUuDDYOTP
  34. ZODFcubPdOLIfoKPmIGZq4qcrIGasYedsYOgs4eiv5euvoSjwIapx4KozYSrzI6wzoaw1Iux1Y+1
  35. 1oq12JSyz5K00Ji305i72qC706C92Z3B3JnA4aTC26vF3KXI5K/Q6s/CjtTOgdvGjtLHmtPNltTP
  36. odTQreXRgunXk+nZp+/ki+zimu/lqQAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAP8ALAAAAABAAEAA
  37. AAj/AP8JHEiwoEGB16qdiVMmzh1p1KhNi1bnzBk809Ic3MixI0czNKhUK5du3bl06cqpVGlOnTpz
  38. 5M60cOOxps2BaSDI+faNGzdx38B92zYunE+f4cQdNTdFg52bUA+mMTCHULdAe7JtA1SIkCBtgsIS
  39. 8hookLay274I0Bi17b8GFgqN+XFmWpQvgPj48ZNXr19Affj0yetHhQK3UeEs+CBGBbSBV4SImSyG
  40. Dx/KYsLwGZN5cpcAZhDflENgAgG2AxEE2SJmi+stXMQc6UK7y5HbRwgcFl3zzYTfjwl2kLCDyBYj
  41. Ro4kx32EyG0iQwoEyMPbo5XfE1ALnODBwwcdO8IH/9kRpHx5HkF6iCAQAEP1jlh+W4AR/N+ZCRs+
  42. 6Peuvz//Dx2Yxp577230hQUfnCACGNhY84YIGXwgggggiKBfB/oh6MEEFkRAwIcCEFigQW+ssEIQ
  43. K4jgww8liGDiixNeiOAH+VGwwAIftjfiQXGUMEQRQwzxYnpDCCFkihd+YAEHHFhgwQQIgCjijgPF
  44. QcILLwjxgwo9/PCCl1i+oIIJImA4o5MdQklAiFQWBA0ba8S5RhppoNEGGmiwkQYdU2DIJJpoYkfA
  45. AFO2CVUaC8gHYAdocvDboIW6NcUUL6DQggssXM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88. AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
  89. AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
  90. AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
  91. AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
  92. AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
  93. AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
  94. AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAAP8ALAAAAABAAEAA
  95. AAj/AP8JHEiwoEGBARIqXMhQ4cGHECNCbEixYkKJGDMOtMixosaPBzuKbAiyJMKRKAOYBEnyZEqG
  96. KzXCJPhyZkyJNl3WvHgzYs5/Oxf29GkzqNChD42KRJpUKUemIZ1ahGpQ6lSqNK1SxLqy5lCtL4F6
  97. JAo2pdixUcua7ZhWLcqzVze6DTsy69y3dXXeXfoW7l62eP/mDSwYcGGweg8r9avYaOLGXhlDNvtY
  98. 8M3JdieHlax5cOedlT8bFr2ZtFfTFwmLDg0TNWuhpjNPjS13dOeqtjW33bq6qcfPOH9DRhqZK8u7
  99. xl8vTr43OWerzpszd1rb4XTHsqMvr65SO3a/zpUXEw+vNrzs7ea5j09fEDT74GyZBgQAOw=='''
  100.  
  101. tf = tempfile.mktemp(".png", "pylogo_x")
  102. print tf
  103.  
  104. def img2b64(source, target, folder = u'Python\\images\\', dir = u'E:\\'):
  105.     try: os.mkdir(dir+folder)
  106.     except: pass
  107.     img2txt = base64.encodestring(open(dir+folder+source,"rb").read())
  108.     f = open(dir+folder+target+'.txt', "w")
  109.     f.write(img2txt)
  110.     f.close()
  111.    
  112.     if 1:
  113.         txt2img = base64.b64decode(img2txt)
  114.         f = open(dir+folder+target+'.png',"wb")
  115.         f.write(txt2img)
  116.         f.close()
  117.     return img2txt
  118. #
  119. '''
  120. try: # just for a quick ref
  121.     take=u'64x64.gif'
  122.     filename = 'pylogo'
  123.     img2b64(take,filename)
  124. except: print "Was Unable To Create Demo Files"
  125. '''
  126.  
  127. ### ??? StringIO... ZZZ
  128. g = open(tf, 'wb')
  129. g.write(base64.decodestring(py_png_b64))
  130. g.close()
  131.  
  132. png = Image.open(tf)
  133.  
  134. g = open(tf, 'wb')
  135. g.write(base64.decodestring(b64mask))
  136. g.close()
  137.  
  138. png_mask = Image.open(tf)
  139. img_mask=Image.new(png_mask.size, mode='1')
  140.  
  141. img_mask.blit(png_mask)
  142.  
  143. ### ---
  144.  
  145. def star_5pt(x,y,s):
  146.     a,b,c,d,e,f,g,h,j,k,m,n,p = 0,180,294,476,250,192,308,500,340,402,357,96,157
  147.     plot_xy = [(a,b),(f,b),(e,a),(g,b),(h,b),(j,c),(k,d),(e,m),(n,d),(p,c)]
  148.     nova=[]
  149.     for xy in plot_xy:
  150.         xy = (xy[0]*0.002)*s+x,(xy[1]*0.002)*s+y
  151.         nova.append(xy)
  152.     return nova
  153.  
  154. star = star_5pt(30,60,300)
  155.  
  156. img.clear((0,128,255))
  157. img.polygon((star), outline=(0,255,0), width=10, fill=(255,255,0))
  158. img.blit(png, target=(100,120), mask=img_mask)
  159.  
  160. draw(())
  161.  
  162. lock = e32.Ao_lock()
  163. appuifw.app.exit_key_handler = lambda:lock.signal()
  164. lock.wait()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement