0

I am a new python programmer and I am trying to use the ImageEnhance module to create a set of images that increase sharpness over time.

The script below works with one problem: the new images are being save to a temporary directory that quickly deletes the files.

How do I alter the save function to point to a proper directory.

Thanks in advance.

#import modules
import sys  
import os
import Image, ImageEnhance,

#find directory, load picture
os.chdir ("/Users/ericmaie/Desktop/test")
backup_directory = "/Users/harddrive/Desktop/test2"

counter = 1

while (counter < 5):

    ima = Image.open("1.png")
    enhancer = ImageEnhance.Sharpness(ima)
    factor = (counter + 10) / 4.0
    enhancer.enhance(factor).show("Sharpness %f" % factor)
    ima.save(str(counter) + '.jpg')

counter = counter + 1

3 Answers3

2

You are creating the enhanced version of the image:

enhancer.enhance(factor).show("Sharpness %f" % factor)

... then promptly throwing it away because it is never stored in a variable. Naturally it is not being saved, because you are not saving it.

Instead, store the enhanced image in its own variable, e.g.:

enhanced = enhancer.enhance(factor)
enhanced.show()
enhanced.save(str(counter) + ".jpg")

The .show() command does save the image, but only incidentally, because it can't hand it off to a viewer app without doing that. This temporary file is deleted as soon as possible, as you've discovered.

kindall
  • 178,883
  • 35
  • 278
  • 309
1

You can save the modified image by replacing the 'show' with 'save'.

path="C:\\Your\\targetFolder\\"
enhancer.enhance(factor).save(path, quality=100)
ninehundred
  • 231
  • 1
  • 7
0

Have you tryed something like this?

path="C:\\Somewhere\\myproperdirectory\\"
ima.save(path+str(counter) + '.jpg')
piertoni
  • 1,933
  • 1
  • 18
  • 30
  • No, unfortunately that doesn't it work. It saves the original copy of the file but not the one that has been sharpened that exists in the temporary directory. I don't seem to be able to attain access to the file that exists in the temporary directory. Other thoughts? thanks – captaindogface May 21 '12 at 00:42
  • It's because you are saving ima – piertoni Jun 15 '12 at 08:53
  • I see, you are opening "ima", then you create "enhancer" as a modified version of "ima", but the error is that finally you save "ima", instead you should save "enhancer" version of the image – piertoni Jun 15 '12 at 08:56