pil

Approaches to resize an uploaded image of unknown format with Python

PIL is great for resizing an image 99% of time. But as there are some formats which PIL cannot handle, e.g. interlaced PNG images, I wonder is there any other libraries to work with as a supplement to PIL when we encounter a unsupported image. Besides interlaced PNG images, what other formats are not currently supported by PIL? As users...

Fractal image scaling with Python

I am in a position where relatively low resolution images are provided (via an API, higher resolution images are not available) and high resolution images need to be generated. I've taken a look at PIL and it's just great for about everything... Except scaling up images. It has the common resizing algorithms: Nearest Neighbor Bilinea...

How to resize just uploaded image?

In VIEW I want to resize uploaded image and save 2 copies of it in model real and changed ...

Unable to use PIL after installing using pythononmac.org package (Mac OS Leopard)

I'm trying to use PIL for a Google App Engine project. I've installed PIL using the installer from pythononmac.org but it doesn't seem to do anything, or at least neither I nor Python can find the files. I'm running Python 2.5.1. ...

Multiplying a tuple by a scalar

I have the following code: print img.size print 10 * img.size this will print (70, 70) (70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70, 70) while I'd like it to print (700, 700) Is any way there to do this without having to write print (10 * img.size[0], 10 * img.size[1]) PS: img.size is a PIL imag...

Function not being called in Python, why? and how can I solve it?

Hello, I am currently working on python/django site, at the moment I have a template that looks like this {% extends "shopbase.html" %} {% block pageid %}products{% endblock %} {% block right-content %} <img src="{{MEDIA_URL}}/local/images/assets/products.png" alt="Neal and Wolf News" class="position"/> <div class="products"> ...

Django / Python / PIL / sorl-thumbnail generation in bulk - memory error

hi folks! I'm trying to bulk generate 4 thumnails for each of around 40k images with sorl-thumbnail for my django app. I iterate through all django objects with an ImageWithThumbnailsFieldFile, and then call its generate_thumbnails() function. This works fine, except that after a few hundred iterations, I run out of memory and my loop ...

What should i use for a Remote Desktop Control?

Hi everybody i'm new to stackoverflow and to python programming :-) Can somebody point me in the right direction or suggest me a good way to do this..? The software I'd like to write is a kind of "multiple remote control", it has: One Server ... whose task is to send his screen to all the clients Many Clients ... they show the Serv...

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. ...

Any way to make nice antialiased round corners for images in python?

Is there any way to make nice round corners with python? Currently PIL and GD2 are used in my project. Both of them have an arc() method, that allows you to draw a quater-circle, but the quater-circle is not antialiased, so the image looks crispy. Is there any neat way to make antialiased/smooth round corners? ...

Having trouble installing PIL in Snow Leopard

I followed these instructions: http://proteus-tech.com/blog/cwt/install-pil-in-snow-leopard/ And everything went as described. However, at the end, I tried running: python selftest.py to verify that everything is working properly, but I get: *** The _imaging C module is not installed I then run the python interpreter and tried...

Validate image size in django admin

I see a lot of people with Django apps that have image uploads are automatically resizing the images after they are uploaded. That is well and good for some cases, but I don't want to do this. Instead, I simply want to force the user to upload a file that is already the proper size. I want to have an ImageField where I force the user t...

Django form in Google App Engine unable to find module PIL.

There are actually a couple of questions here. For what I'm doing, I'm doing a basic image upload with Django 1.1 and Google App Engine. Here is my form class: class UploadPictureForm(forms.Form): picture = forms.ImageField() And then on submit, I have the following code: def handle_picture(request): form = UploadPictureFor...

How to combine multiple images fast for page views counter

How can I combine multiple images, such as base image with logo and number of digits images to display graphical counter with pageviews count, updated dynamically? It should be very fast, with thousands of renders per second. User should see counter image without Javascript and with single img tag. I prefer to implement that counter wi...

Methods to create text preview from a font

I'm currently using ImageMagick's convert command to create text preview (.png) from .ttf font file. Overall, it's better in auto text positioning despite it failed to read some valid .ttf file sometimes. The speed is not great but acceptable. PIL's ImageFont looks like is not good at text aligning, often prints bottom-left corner of fi...

fonts clipping with PIL

This image was created with PIL. See how the g's and the y's are cut off in this image? How can I prevent this? The code that created this image is pretty straight forward (abbreviated): import Image, ImageDraw, ImageFont im = Image.new("RGBA", (200, 200), 'white') draw = ImageDraw.Draw(im) font = ImageFont.truetype("VeraSe.ttf", 1...

changing image resolution in Python for a .bmp file

hi, I want to change the resolution of the .bmp image in python. ( i.e. the pixel/inch information) . Using PIL, for jpg image, for instance, the following code works fine import Image im = Image.open("myImg.jpg) im.save("output.jpg", dpi = (75, 75) ) If you view this in some image editing software like GIMP, it shows the Pixel per...

How to get alpha value of a PNG image with PIL?

How to detect if a PNG image has transparent alpha channel or not using PIL? img = Image.open('example.png', 'r') has_alpha = img.mode == 'RGBA' With above code we know whether a PNG image has alpha channel not not but how to get the alpha value? I didn't find a 'transparency' key in img.info dictionary as described at PIL's website ...

ImageFont's getsize() does not get correct text size?

I use the following two methods to to generate text preview image for a .ttf font file PIL method: def make_preview(text, fontfile, imagefile, fontsize=30): try: font = ImageFont.truetype(fontfile, fontsize) text_width, text_height = font.getsize(text) img = Image.new('RGBA', (text_width, text_height)) ...

Size differences between TrueType and OpenType fonts when using PIL ImageFont

I'm trying to create PNGs of letters from the fonts on my system. Seems to work okay with TrueType fonts (.ttf) but not OpenType (.otf). The images formed are the same size but the actual letters appear much smaller with OpenType - see below. I'm using the ImageFont module from the Python Imaging library. There doesn't seem to be a way ...