| | |
Overlaying graphics in Python?
![]() |
•
•
Join Date: Jun 2008
Posts: 2
Reputation:
Solved Threads: 0
Is there a way to overlay graphics in Python? I'm looking for functionality similar to X-fire. That is, I want to be able to press a set of keys in a game and a GUI screen with some options (possibly a shell script) that doesn't cover up the game should come up without the need to alt+tab.
I would like to do this because the games I'm playing respond very negatively to alt+tabbing but X-Fire works fine in them. I've looked everywhere for a solution but have yet to find one.
I would like to do this because the games I'm playing respond very negatively to alt+tabbing but X-Fire works fine in them. I've looked everywhere for a solution but have yet to find one.
Here is an example using PIL ...
I hope that is the sort of thing you meant.
python Syntax (Toggle Plain Text)
# generate a true opaque watermark with the Python Image Library (PIL) # free download from: http://www.pythonware.com/products/pil/ from PIL import Image, ImageEnhance def reduce_opacity(im, opacity): """returns an image with reduced opacity""" assert opacity >= 0 and opacity <= 1 if im.mode != 'RGBA': im = im.convert('RGBA') else: im = im.copy() alpha = im.split()[3] alpha = ImageEnhance.Brightness(alpha).enhance(opacity) im.putalpha(alpha) return im def watermark(im, mark, position, opacity=1): """adds a watermark to an image""" if opacity < 1: mark = reduce_opacity(mark, opacity) if im.mode != 'RGBA': im = im.convert('RGBA') # create a transparent layer the size of the image and draw the # watermark in that layer. layer = Image.new('RGBA', im.size, (0,0,0,0)) if position == 'tile': for y in range(0, im.size[1], mark.size[1]): for x in range(0, im.size[0], mark.size[0]): layer.paste(mark, (x, y)) elif position == 'scale': # scale, but preserve the aspect ratio ratio = min( float(im.size[0]) / mark.size[0], float(im.size[1]) / mark.size[1]) w = int(mark.size[0] * ratio) h = int(mark.size[1] * ratio) mark = mark.resize((w, h)) layer.paste(mark, ((im.size[0] - w) / 2, (im.size[1] - h) / 2)) else: layer.paste(mark, position) # composite the watermark with the layer return Image.composite(layer, im, layer) def test(): # pick images you have ... im = Image.open('Audi.jpg') mark = Image.open('Audi2.jpg') watermark(im, mark, 'tile', 0.3).show() # also try these ... #watermark(im, mark, 'scale', 0.3).show() #watermark(im, mark, (10, 10), 0.5).show() if __name__ == '__main__': test()
May 'the Google' be with you!
•
•
Join Date: Jun 2008
Posts: 2
Reputation:
Solved Threads: 0
•
•
•
•
Here is an example using PIL ...
I hope that is the sort of thing you meant.python Syntax (Toggle Plain Text)
# generate a true opaque watermark with the Python Image Library (PIL) # free download from: http://www.pythonware.com/products/pil/ from PIL import Image, ImageEnhance def reduce_opacity(im, opacity): """returns an image with reduced opacity""" assert opacity >= 0 and opacity <= 1 if im.mode != 'RGBA': im = im.convert('RGBA') else: im = im.copy() alpha = im.split()[3] alpha = ImageEnhance.Brightness(alpha).enhance(opacity) im.putalpha(alpha) return im def watermark(im, mark, position, opacity=1): """adds a watermark to an image""" if opacity < 1: mark = reduce_opacity(mark, opacity) if im.mode != 'RGBA': im = im.convert('RGBA') # create a transparent layer the size of the image and draw the # watermark in that layer. layer = Image.new('RGBA', im.size, (0,0,0,0)) if position == 'tile': for y in range(0, im.size[1], mark.size[1]): for x in range(0, im.size[0], mark.size[0]): layer.paste(mark, (x, y)) elif position == 'scale': # scale, but preserve the aspect ratio ratio = min( float(im.size[0]) / mark.size[0], float(im.size[1]) / mark.size[1]) w = int(mark.size[0] * ratio) h = int(mark.size[1] * ratio) mark = mark.resize((w, h)) layer.paste(mark, ((im.size[0] - w) / 2, (im.size[1] - h) / 2)) else: layer.paste(mark, position) # composite the watermark with the layer return Image.composite(layer, im, layer) def test(): # pick images you have ... im = Image.open('Audi.jpg') mark = Image.open('Audi2.jpg') watermark(im, mark, 'tile', 0.3).show() # also try these ... #watermark(im, mark, 'scale', 0.3).show() #watermark(im, mark, (10, 10), 0.5).show() if __name__ == '__main__': test()
I'm trying to create an overlay that will cover a full-screen game without minimizing it, allowing you to interact with a GUI that doesn't cover up your entire game or cause it to minimize. You should be able to type text in the GUI and click buttons without it interfering with the game in any way aside from intercepting mouse clicks and keyboard commands. My hope at the moment is to put a functioning python shell into the game (just for starters).
A program that does what I'm trying to accomplish is x-fire www.xfire.com
Last edited by Timotei; Jun 7th, 2008 at 7:22 pm.
![]() |
Other Threads in the Python Forum
- Previous Thread: Python Beginner Help (Calculator)
- Next Thread: File IO and pictures
| Thread Tools | Search this Thread |
abrupt ansi anti approximation assignment avogadro backend beginner binary bluetooth calculator character cmd code customdialog cx-freeze data decimals dictionaries dictionary directory dynamic error examples exe file float format function gnu graphics gui heads homework http ideas import input itunes java launcher leftmouse line linux list lists loop module mouse number numbers output parsing path pointer port prime programming progressbar projects push py2exe pygame pyglet pyqt python random recursion schedule screensaverloopinactive script scrolledtext sqlite ssh statistics string strings sudokusolver sum table terminal text thread threading time tlapse tricks tuple tutorial twoup ubuntu unicode urllib urllib2 variable ventrilo wikipedia write wxpython xlib






