Lower the brightness of all RGB pixels by 20% in Python?
<p>I have been trying to teach myself more advanced methods in Python but can't seem to find anything similar to this problem to base my code off of. </p>

<p>First question: Is this only way to display an image in the terminal to install Pillow? I would prefer not to, as I'm trying to then teach what I learn to a very beginner student. My image.show() function doesn't do anything. </p>

<p>Second question: What is the best way to go about lowering the brightness of all RGB pixels in an image by 20%? What I have below doesn't do anything to the alter the brightness, but it also can compile completely. I would prefer the most simple way to go about this as far as importing minimal libraries. </p>

<p>Third Question: How do I made a new picture instead of changing the original? (IE- lower brightness 20%, "image-decreasedBrightness.jpg" is created from "image.jpg") </p>

<p>here is my code - sorry it isn't formatted correctly. Every time i tried to indent it would tab down to the tags bar. </p>

<pre><code>import Image
import ImageEnhance

fileToBeOpened = raw_input("What is the file name? Include file type.")
image = Image.open(fileToBeOpened)

def decreaseBrightness(image):
    image.show()
    image = image.convert('L')
    brightness = ImageEnhance.Brightness(image) 
    image = brightness.enhance(20) 
    image.show() 
    return image

decreaseBrightness(image)
</code></pre>

<p>To save the image as a file, there's an example on the documentation:</p>

<pre><code>from PIL import ImageFile

fp = open("lena.pgm", "rb")

p = ImageFile.Parser()

while 1:
    s = fp.read(1024)
    if not s:
        break
    p.feed(s)

im = p.close()

im.save("copy.jpg")
</code></pre>

<p>The key function is <code>im.save</code>.</p>

<p>For a more in-depth solution, get a nice beverage, find a comfortable place to sit and enjoy your read:
<a href="https://pillow.readthedocs.io/en/3.4.x/" rel="nofollow">Pillow 3.4.x Documentation</a>.</p>

python image