Advertisement
here2share

# Tk_img_fadeout.py

Sep 6th, 2018
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.83 KB | None | 0 0
  1. # Tk_img_fadeout.py
  2.  
  3. from Tkinter import *
  4. import tkFileDialog
  5. from cStringIO import StringIO
  6. from PIL import ImageTk, ImageDraw, ImageChops, Image
  7. import base64, zlib
  8.  
  9. root = Tk()
  10. root.geometry("360x640+0+0")
  11. canvas = Canvas(root, width=360, height=640)
  12. canvas.pack()
  13.  
  14. oFiletype =("png files","*.png"),("all files","*.*")
  15. def b64_zlib():
  16.     """Convert a file (specified by a path) into a data URI."""
  17.     path = tkFileDialog.askopenfilename(title = "Select file",filetypes=oFiletype)
  18.     try:
  19.         with open(path, 'rb') as fp:
  20.             data = fp.read()
  21.             compressed = zlib.compress(data)
  22.             b64 = base64.encodestring(compressed)
  23.         return b64
  24.     except:
  25.         print ">>> acceptable image not selected <<<"
  26.  
  27.  
  28. b64='''\
  29. eJzlVok7FNobPpipmRHG2MYgjF2SLWNLxjq2CbkydWlIaFGKQkUMRaXQLYw21XXJLZRIpcWSpZsQ
  30. spQsCWVJ9nW+37j3z/id5znn/b7vfOd5z3nPc5ZzbkwHEQKFgBAScWTYevAxm18zcUL81tOE1MMH
  31. gTAPB2tU8F7+O9/BBNFd6Qg9TBFe9sMiJITcXDzt+HE8np86ghAPyQAFgYzMiLT0HNIEZAhaCIwQ
  32. mKAZEwTa2q00Wquq6qK5+XcLi0XkCMgNUCCgSGAi2IF4xxAwmd329t9sbBZZrOEdO5b37/8UGPgt
  33. KGgpMnKB0kURGhbikyCQIveRpQHJLMggUEdgbNhtqAqIBkhtRE17Sdviu4XpsikCOwTbEQQjCOdT
  34. 7QC0F9CxFWQ3bue06OQ+4+7F82JNsHYu7tw/vD+YF3xs5FjEQgSKA8QFlAuoFBAkIEhHcAfBM1QP
  35. qJ0fqUbwEX3nG0OIx5MBUAMwAWAARAA0Skt/ERTsERFp4xuKih+1tD7r6Y0jNColN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. RO8F+3Ej0e+nQf2u7uY6NZVNezRGfdZs15MOiPATU23Jo+soBOfIrGPuMRv1UI5xVRDu2v1qH/E9
  77. iTYq7tVzSOHC7wYvyHINjFl1CegzkR7YZl1DLnbmRhIInNGWcck/JUyIDwOcThvr4iefp1rU3EsR
  78. V6SnvnCp85m3q74s/vKZEo4n9zQgb+gXo/pDnHusknfp10vdcf0yMrb0Ur9N5A7Zel3sbQkqngLX
  79. g/s9Tbz92vEfMoJU6bMzZWtvD1PivM2KtKh40u7HhLIDWZRZrTlsnWQadmFEtVzxE1uR2r+7OJrE
  80. OWjT7lW19YwyKU0yfLmembPJZbr1FOVhQCj3giNhslFiJDDSwL9edcWTzks7yD07imfMz+6aXtlt
  81. 5kCey+pjaWSnaGf2cK9HxWGCMTM9qY9u01xOu5Oa8ZPbrsRQqsRHscnhsg+UeooKDcQcBr8GEQde
  82. SYxf1Xu3JzqBjBEupGYmn0qk1Mxsn5NhkwZ+dmxxKtnhOrtiWqPjPW92ud7257qFlp9s2/1FuMnD
  83. d15U2uzVjIhsAJf+PVIDt06u2F9kt59OMugl6nhOnXgYdLsJ+9ToGaNnbVsvKeDGqfgqsfLPUn0Y
  84. X9GtflUbGTGF4eT1c/RyYYsQ/gurKU8jk+wvUSa1b4os7I8YYkQ80fERyGK/9nNrPkK9mdYhpm6W
  85. vPRI0KcpyK3kaFhBgeVg5LKXzZO3TuQ34ffuP16WuUFwnrjLTmF7zeIC99JkdCR5YrkfK/4KNTmz
  86. c/Xf6mjHtC2wZnP+B/XTMrY='''
  87.  
  88. # b64 = b64_zlib()
  89.  
  90. if b64:
  91.     print "b64_zlib='''\\\n"+b64+"'''"
  92.     b64 = base64.decodestring(b64)
  93.     zzz = StringIO(zlib.decompress(b64))
  94.     img = Image.open(zzz)
  95.     wt,ht = img.size
  96. #
  97. class Cv(): pass
  98. cv=Cv()
  99. #
  100. def oRGB(z):
  101.     pixels = image.load()
  102.     for i in range(wt):
  103.         for j in range(ht):
  104.             r, g, b, a = pixels[i, j]
  105.             if a:
  106.                 pixels[i, j] = (r,g,b,z)
  107.     photo = ImageTk.PhotoImage(image)
  108.     try: canvas.delete(imgx)
  109.     except: 0
  110.     imgx = canvas.create_image(100, 100, image=photo, anchor="center")
  111.     root.update()
  112. #
  113. image = img.convert("RGBA")
  114. canvas = Canvas(root, width=200, height=200)
  115. canvas.place(relx=0.5, rely=0.5, anchor="center")
  116. #
  117. while 1:
  118.     for z in range(256,1,-2):
  119.         oRGB(z)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement