tags:

views:

74

answers:

3

What I'm trying to do:

I want to give the user the ability to upload a picture that is any size. This image is then resized if it is over 1024 wide or over 768 high. It then resizes the image to be within those bounds, but keeping proportions. Then it adds a semi-transparent watermark to the lower right corner, and saves the file.

Before it adds the watermark, it will create a copy of the image and resize it down to a thumbnail size (also keeping proportions) and saves it in a separate folder.

The Problems with PIL:

As far as resizing goes, I was hoping it would have a way to do smart resizing (keep proportions). Also, I didn't seem to have much control over the quality level when saving it as a JPEG. I had to save it as a PNG to keep full quality which was pretty heavy.

For the thumbnail, it sounds that it might be pretty difficult, reading through the documentation of PIL, but I could be wrong.

The Question

Are there any other, more advanced image libraries for Python that may be a bit more up to date, or include some features that I am looking for? Are there any public functions that do what I'm looking for that I could use? I don't mind writing this stuff myself, but wanted to check first. Thanks!

+1  A: 

As far as resizing goes, I was hoping it would have a way to do smart resizing (keep proportions).

Seeing as this is probably one or two lines in Python, I don't see why this needs to be in the interface of the library.

Also, I didn't seem to have much control over the quality level when saving it as a JPEG.

Quoting the handbook:

The save method supports the following options:

quality

The image quality, on a scale from 1 (worst) to 95 (best). The default is 75. Values above 95 should be avoided; 100 completely disables the JPEG quantization stage.

Did you try that? If so, why didn't it help?

Jim Brissom
+1  A: 

Agree with Jim about proportions. You are talking about such a trivial operation that can easily be inlined wherever, that I wouldn't even look for the feature/option in the API to be honest. The moment you call .resize(factor = 0.8, keepRatio = True ), you're typing the same amount of text of punching in .resize(hFactor = 0.8, vFactor = 0.8).

As for libraries, you could have a look at imageMagick with PythonMagick: http://www.imagemagick.org/script/index.php

It does resizing (with respectable interpolators) and writes to several formats, offers text overlays out of the box, or simple compositing if you have your own watermark you want to paste in.

Used that and not PIL in the last couple places where I had to deal with the problem, and for the simple stuff i needed I was satisfied, that was through magick++ though, not with the Python bindings, but I doubt the experience would be very different. Completely out of touch with PIL though, so I don't know how it would compare.

ThE_JacO
I had the same problem and used imagemagick too (the command line version) - it's simple, easy and you don't have to know anything about images.
THC4k
A: 

In a pinch, convert the Image to a numpy array, modify it as you please, and convert back.

Paul Harrison
Could you please explain this a bit? Do they have some sort of image manipulation built in, or am I just dealing with a large array.
Shane Reustle
Treating your image as a large array is exactly what I am suggesting. For example, if you wanted to do some sort of exceptionally funky watermarking that involved more than overlaying a transparent image.
Paul Harrison