Tag Archives: PIL
If you load a GIF file with PIL via Image.open(‘giffile.gif’) and then try to look at its pixels, you would get integers instead of tuples since the GIF pixels refers to one of the 256 colours in the GIF colour palette. The palette would then contain the RGB value of the pixel.
To avoid all this hassle and just get RGB tuple directly:
gif = Image.open('giffile.gif')
rgbimage = GIF.convert ('RGB')
rgbimage.getpixel((0,0))
>>>(231, 10, 54)
1 comment | tags: GIF, image, PIL, Python, RGB | posted in Tips
Used a NumPy array. Doesn’t work if the diagonal+1s are white of course.
import Image
from numpy import array, zeros, uint8
line = Image.open('wire.png')
# third dimension is for colours
a = zeros((100, 100, 3), dtype=uint8)
step = array([0, 1])
position = array([0, 0])
count = 0
# continue until when the next spot expected to be unfilled is filled
while not max(a[tuple(position)]):
# paint colour
a[tuple(position)] = array(line.getpixel((count, 0)))
# if reached a wall
if max(position + step) > 99 or min(position + step) < 0 or max(a[tuple(position + step)]):
# change direction
step = (abs(step) ^ 1) * (-step[0] if step[0] else step[1])
# advance
position += step
count += 1
# convert to image
Image.fromarray(a).save('swirl.jpeg')
Leave a comment | tags: array, challenge, NumPy, PIL, puzzle, Python | posted in Thoughts
The interweb seem to incline on py2app when it come to deploying applications on mac. I’ve tried to make a single deployable .app file for my application for a long time trying to follow these instructions from ars technica. I’m not a hacker and just want to produce a deployable usable application for others to use. And it seems py2app from MacPorts wasn’t able to surmount the Snow Leopard’s 64-bit compatibility issue.
And then, I was slacking off while studying for my final and out of nowhere I found PyInstaller‘s explicit support for PyQt and its recent support for the mac. And after trying, almost everything works out without much of a kink. Credit goes to ChrisWayg who produced an amazingly complete and up-to-date set of instructions to follow. I’m merely telling how my application did using his instructions (April 2010) and hopefully doing my part to draw more attention to the excellent PyInstaller. Continue reading
Leave a comment | tags: Apple, application, Deployment, Mac, PIL, py2app, PyInstaller, PyQt, Python, Qt, Snow Leopard | posted in Tips
This simple tutorial shows how you can create a program with Python and Qt to allow for image files from Explorer/Finder/Nautilus to be dropped in a list widget and create list items with thumbnails

First we subclass a QListWidget to handle events
Continue reading
4 comments | tags: drag, drag-and-drop, drop, explorer, file, image, picture, PIL, PyQt, Python, QListWidget, Qt, thumbnail | posted in Tips