Sam Weisenthal
Sam Weisenthal

Reputation: 2951

Blur image with python

I'm trying to blur the image in the pwd and then save it to a new file:

from PIL import Image 
import glob, os

size = 128, 128
from PIL import ImageFilter

for infile in glob.glob("*.jpg"):
    print "processing %s\n" % infile
    file, ext = os.path.splitext(infile)
    print " file %s, extension %s\n" % (file, ext)
    im = Image.open(infile)
    #im.thumbnail(size, Image.ANTIALIAS)
    #im.save(file + "thumb", "JPEG")
    im.filter(ImageFilter.BLUR)
    im.save(file + "blurred2", "JPEG")

What's saved looks exactly like the original image, however.

Upvotes: 0

Views: 2522

Answers (2)

lakshmen
lakshmen

Reputation: 29094

You need to assign the filtered image to a new image.

im1 = im.filter(ImageFilter.BLUR) 

Code example:

import ImageFilter

def filterBlur(im):

    im1 = im.filter(ImageFilter.BLUR)

    im1.save("BLUR" + ext)

filterBlur(im1)

Upvotes: 3

Avinash Babu
Avinash Babu

Reputation: 6252

You can just do

blurred_image = original_image.filter(ImageFilter.BLUR)

See image filter modules for more works ..:)

i would recommend you to read this.

Upvotes: 2

Related Questions