I’m using the Python Imaging Library for some very simple image manipulation, however I’m having trouble converting a greyscale image to a monochrome (black and white) image. If I save after changing the image to greyscale (convert(‘L’)) then the image renders as you would expect. However, if I convert the image to a monochrome, single-band image it just gives me
Tag: python-imaging-library
Write image to Windows clipboard in python with PIL and win32clipboard?
I’m trying to open an image file and copy the image to the Windows clipboard. Is there a way to fix this: I could install PythonMagick, etc., but would prefer not installing yet another library for a one-off program Answer
PIL’s colour space conversion YCbCr -> RGB
The algorithm used by PIL v1.1.7 gives ‘washed out’ looking results. When converting the same source data using ffmpeg it looks correct. Using mplayer gives identical results to ffmpeg (perhaps they use the same library underneath). This leads me to believe PIL may be stuffing up the colour space conversions. The conversion seems to be sourced in libImaging/ConvertYCbCr.c: This is
PIL – libjpeg.so.8: cannot open shared object file: No such file or directory
Compiled the libjpeg v8, PIL 1.1.7 and and import for _imaging works on the system Python, but spouts this error inside the virtualenv: here is the error run with a python -v interpreter inside the virtualenv and here are the paths: I am using Ubuntu 10.10 and this is the uname-a output: I am using Python 2.6 I followed the
How to merge a transparent png image with another image using PIL
I have a transparent png image foo.png and I’ve opened another image with: Now what I need is to merge foo.png with foo2.png. (foo.png contains some text and I want to print that text on foo2.png) Answer First parameter to .paste() is the image to paste. Second are coordinates, and the secret sauce is the third parameter. It indicates a
Python: The _imagingft C module is not installed
I’ve tried lots of solution that posted on the net, they don’t work. So the system can find the _imaging but still can’t use truetype font Raises this error: Answer Your installed PIL was compiled without libfreetype. You can get precompiled installer of PIL (compiled with libfreetype) here (and many other precompiled Python C Modules): http://www.lfd.uci.edu/~gohlke/pythonlibs/
Center-/middle-align text with PIL?
How would I center-align (and middle-vertical-align) text when using PIL? Answer Deprecation Warning: textsize is deprecated and will be removed in Pillow 10 (2023-07-01). Use textbbox or textlength instead. Code using textbbox instead of textsize. Result Use Draw.textsize method to calculate text size and re-calculate position accordingly. Here is an example: and the result: If your fontsize is different, include
Draw bold/italic text with PIL?
How to draw bold/italic text with PIL? ImageFont.truetype(file, size) has an option to specify font size only. Answer Use the bold/italic version of the font
How to use PIL to make all white pixels transparent?
I’m trying to make all white pixels transparent using the Python Image Library. (I’m a C hacker trying to learn python so be gentle) I’ve got the conversion working (at least the pixel values look correct) but I can’t figure out how to convert the list into a buffer to re-create the image. Here’s the code Answer You need to