pil

How do I convert any image to a 4-color paletted image using the Python Imaging Library ?

I have a device that supports 4-color graphics (much like CGA in the old days). I wanted to use PIL to read the image and convert it using my 4-color palette (of red, green, yellow, black), but I can't figure out if it's even possible at all. I found some mailing list archive posts that seem to suggest other people have tried to do so ...

How do I draw text at an angle using python's PIL?

Using Python I want to be able to draw text at different angles using PIL. For example, imagine you were drawing the number around the face of a clock. The number 3 would appear as expected whereas 12 would we drawn rotated counter-clockwise 90 degrees. Therefore, I need to be able to draw many different strings at many different angl...

How can I draw a bezier curve using Python's PIL?

I'm using Python's Imaging Library and I would like to draw some bezier curves. I guess I could calculate pixel by pixel but I'm hoping there is something simpler. ...

Python with PIL and Libjpeg on Leopard

I'm having trouble getting pictures supported with PIL - it throws me this: "IOError: decoder jpeg not available" I installed PIL from binary, not realizing I needed libjpeg. I installed libjpeg and freetype2 through fink. I tried to reinstall PIL using instructions from http://timhatch.com/ (bottom of the page) "* Download PIL 1.1....

How do I resize an image using PIL and maintain its aspect ratio?

Is there an obvious way to do this that I'm missing? I'm just trying to make thumbnails. ...

Converting a PDF to a series of images with Python

I'm attempting to use Python to convert a multi-page PDF into a series of JPEGs. I can split the PDF up into individual pages easily enough with available tools, but I haven't been able to find anything that can covert PDFs to images. PIL does not work, as it can't read PDFs. The two options I've found are using either GhostScript or Im...

How to generate a filmstrip image in python from a folder of images?

I would like to do the equivalent off this (ruby code) in python for a Django project I am working on. I want to make a filmstrip image of X number of images in a folder. ...

How to complete this python function to save in the same folder?

Hi, I am trying to write my first real python function that does something real. What i want to accomplish is searching a given folder, and then open all images and merging them together so they make a filmstrip image. Imagine 5 images stacked on top of eachother in one image. I have this code now, which should be pretty much ok, but pr...

Having problem importing the PIL image library

Hi, i am trying to do something with the PIL Image library in django, but i experience some problems. I do like this: import Image And then I do like this images = map(Image.open, glob.glob(os.path.join(dirpath, '*.thumb.jpg'))) But when i try to run this i get an error and it leeds me to think that its not imported correctly, a...

How do you draw transparent polygons with Python?

I'm using PIL (Python Imaging Library). I'd like to draw transparent polygons. It seems that specifying a fill color that includes alpha level does not work. Are their workarounds? If it can't be done using PIL I'm willing to use something else. If there is more than one solution, then performance should be factored in. The drawing...

How do I get PIL to work when built on mingw/cygwin?

I'm trying to build PIL 1.1.6 against cygwin or mingw whilst running against a windows install of python. When I do either the build works but I get the following failure when trying to save files. $ python25 Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "li...

PIL and numpy

Alright, I'm toying around with converting a PIL image object back and forth to a numpy array so I can do some faster pixel by pixel transformations than PIL's PixelAccess object would allow. I've figured out how to place the pixel information in a useful 3D numpy array by way of: pic = Image.open("foo.jpg") pix = numpy.array(pic.getda...

Resize image in Python without losing EXIF data

I need to resize jpg images with Python without losing the original image's EXIF data (metadata about date taken, camera model etc.). All google searches about python and images point to the PIL library which I'm currently using, but doesn't seem to be able to retain the metadata. The code I have so far (using PIL) is this: img = Image....

Drawing with Webdings in PIL

I've got a Python program using PIL to render text, and it works great with all kinds of fonts. But it only draws "missing glyph" rectangles with wingdings or webdings. Here's a sample that tries to draw every unicode character: # Run this with .ttf file path as an argument, and also an encoding if you like. # It will make 16 PNGs wit...

Draw rounded corners on photo with PIL

My site is full of rounded corners on every box and picture, except for the thumbnails of user uploaded photos. How can I use the Python Imaging Library to 'draw' white or transparent rounded corners onto each thumbnail? ...

What is the fastest way to draw an image from discrete pixel values in Python?

I wish to draw an image based on computed pixel values, as a means to visualize some data. Essentially, I wish to take a 2-dimensional matrix of color triplets and render it. Do note that this is not image processing, since I'm not transforming an existing image nor doing any sort of whole-image transformations, and it's also not vecto...

PIL vs RMagick/ruby-gd

Hi, For my next project I plan to create images with text and graphics. I'm comfortable with ruby, but interested in learning python. I figured this may be a good time because PIL looks like a great library to use. However, I don't know how it compares to what ruby has to offer (e.g. RMagick and ruby-gd). From what I can gather PIL ...

How to scale an image without occasionally inverting it (with the Python Imaging Library)

When resizing images along the lines shown in this question occasionally the resulting image is inverted. About 1% of the images I resize are inverted, the rest is fine. So far I was unable to find out what is different about these images. See resized example and original image for examples. Any suggestions on how to track down that pr...

numpy, PIL adding an image

I'm trying to add two images together using numpy and PIL. The way I would do this in matlab would be something like: >> M1 = imread('_1.jpg'); >> M2 = imread('_2.jpg'); >> resM = M1 + M2; >> imwrite(resM, 'res.jpg'); I get something like this: Using a compositing program and adding the images the matlab result seems to be right. ...

Python Imaging Library and JPEGs on MacOsX

I've gotten a hold of Python Imaging Library (PIL) and installed the PNG support stuff just fine. I am however having issues with theJPEG Library. The default setting for it is nothing but they suggest "/home/libraries/jpeg-6b". On the Mac that directory doesn't exist, the library is however installed fine, here's the output of the inst...