views:

129

answers:

2

Hi I want to take a BMP or JPG and duplicate it so the new image will darker (or brighrt) what function can I use? Ariel

+6  A: 

You can use ImageEnhance module of PIL:

import Image
import ImageEnhance

image = Image.open(r'c:\temp\20090809210.jpg')
enhancer = ImageEnhance.Brightness(image)
brighter_image = enhancer.enhance(2)
darker_image = enhancer.enhance(0.5)

Look at PIL and ImageEnhance documentation for more details.
Note: I think ImageEnhancer documentation is a bit too terse, and you may need some experimenting within the interactive prompt to get it right.

Roberto Liffredo
A: 

If you want to do it the hard way i.e. code up a pixel by pixel intensity change. Here is how: 1) Convert from RGB to HSI 2) Increase or decrease the Intensity component 3) Conver back from HSI to RGB

True fade out i.e. alpha channel is not present in the JPG or BMP formats [ RGBA format image in PIL] . You get black to white using the the intensity technique. If you want to use alpha use png or tiff instead.

whatnick