1

I writing a Python app where I need to do some image tasks.

I'm trying PIL and it's ImageOps module. But it looks that the unsharp_mask method is not working properly. It should return another image, but is returning a ImagingCore object, which I don't know what is.

Here's some code:

import Image
import ImageOps

file = '/home/phius/test.jpg'
img = Image.open(file)
img = ImageOps.unsharp_mask(img)
#This fails with AttributeError: save
img.save(file)

I'm stuck on this.

What I need: Ability to do some image tweeks like PIL's autocontrast and unsharp_mask and to re-size, rotate and export in jpg controlling the quality level.

RAS
  • 8,100
  • 16
  • 64
  • 86
Phius
  • 725
  • 1
  • 8
  • 15

1 Answers1

1

What you want is the filter command on your image and the PIL ImageFilter module[1] so:

import Image
import ImageFilter

file = '/home/phius/test.jpg'
img = Image.open(file)
img2 = img.filter(ImageFilter.UnsharpMask) # note it returns a new image
img2.save(file)

The other filtering operations are part of the ImageFilter module[1] as well and are applied the same way. The transforms (rotation, resize) are handled by calling functions[2] on the image object itself i.e. img.resize. This question addresses JPEG quality How to adjust the quality of a resized image in Python Imaging Library?

[1] http://effbot.org/imagingbook/imagefilter.htm

[2] http://effbot.org/imagingbook/image.htm

Community
  • 1
  • 1
Rory Hart
  • 1,813
  • 1
  • 19
  • 19
  • Thank you very much, Rory. The other things (rotate, save quality) I was doing already, just posted in case someone sugest another library. =) – Phius Aug 01 '12 at 04:32