0

I have to ask the user for a filename (that exists in the programs father file) and open that .gif file in order to play with the colors of the image... I am really new as programming and need help! I will be asking for more answers soon as well!!

Here is what I have so far:
You can see where my program has to go so help as much as you can/want!!

from graphics import *
import os

def main():
filename = input('Please enter the name of a picture file: ')
#Open .gif filename internally so I can edit it
print()
print('Select your choice:')
print()
print('a. Turn the image blue')
print('b. Convert the image to grayscale')
print('c. Invert the colors of the image')
print('d. Mirror the image from left to right')
print()

#re-ask question if user enters an invalid answer a-d
abort = 0
while abort == 0:
selection = input('Choose a selection: ')
print()
selection = selection.lower()
if selection == 'a':
abort = 1
elif selection == 'b':
abort = 1
elif selection == 'c':
abort = 1
elif selection == 'd':
abort = 1
else:
print('That is not a valid entry! Try again')
print()

def image_blue():
#Change image properties to blue

def image_grayscale():
#Change image to grayscale

def image_invert():
#Invert colors of image

def image_mirror():
#Mirror original image

def save_file():
#Save file to new name and close window

file_save=input('Please enter the file you would like to save to: ')


main()

3
Contributors
6
Replies
7
Views
5 Years
Discussion Span
Last Post by peterson624
0

Please edit your post. And put the code in code tags.

[CODE]
your code
[/CODE]

You'll then get it like this:

your code

Edited by diafol: fixed formatting

0
from graphics import *
Import os

def main():
    filename = input('Please enter the name of a picture file: ')
    #Open .gif filename internally so I can edit it
    print()
    print('Select your choice:')
    print()
    print('a. Turn the image blue')
    print('b. Convert the image to grayscale')
    print('c. Invert the colors of the image')
    print('d. Mirror the image from left to right')
    print()
    #re-ask question if user enters an invalid answer a-d 
    [abort = 0]
    [while abort == 0:]
      [selection = input('Choose a selection: ')]
      [print()]
      [selection = selection.lower()]
      [if selection == 'a':]
        [abort = 1]
      [elif selection == 'b':]
        [abort = 1]
      [elif selection == 'c':]
        [abort = 1]
      [elif selection == 'd':]
        [abort = 1]
      [else:]
        [print('That is not a valid entry! Try again')]
      [print()]

def image_blue():
#Change image properties to blue

def image_grayscale():
#Change image to grayscale

def image_invert():
#Invert colors of image

def image_mirror():
#Mirror original image

def save_file():
#Save file to new name and close window

    file_save=input('Please enter the file you would like to save to: ')


main()]
0

can anyone help me to read all the pixels in a .gif so i can change theie pixel colors....... I have a .gif file in the same file as my python program but i need to be able to read through all the pixels to make the necessary changes whether it be grayscale, b&w, invert, and so on

0

gif is one of the few supported image types supported by tkinter. So you do not need to code yourself for that or use third party modules.

0

Unfortunately we arent allowed to use secondary sources and we have to code it out.... I think if i can figure out how to store all points to a list and all the colors in the width, height, and all in between i can change the color sequence numbers if applicable?! just dont know how to do that in code...

-1

I HAVENT GOTTEN THE GRAYSCALE TO WORK YET... NEED SOME HELP.. HAVENT ATTEMPTED THE OTHER TWO BELOW IT. ANY HELP IS APPRECIATED!!!

from graphics import *
import sys

def main():
    filename = input('Please enter the name of a picture file: ')
    print()
    try:
      img = Image(Point(0,0), filename)
    except:
      tk.TclError()
      print('The selected file cannot be opened')
      sys.exit()
    if img.getHeight() == 0:
      print('The selected file cannot be opened')
      sys.exit()

      
    # Indices of the different color values
    RED = 0
    GREEN = 1
    BLUE = 2


    colors = img.getPixel(0,0)


    print()
    print('Select your choice:')
    print()
    print('a. Turn the image blue')
    print('b. Convert the image to grayscale')
    print('c. Invert the colors of the image')
    print('d. Mirror the image from left to right')
    print()
    abort = 0
    while abort == 0:
        selection = input('Choose a selection: ')
        print()
        selection = selection.lower()
        if selection == 'a':
          abort = 1
          image_blue = blue_pic(filename)
        elif selection == 'b':
          abort = 1
          image_grayscale = grayscale_pic(filename)
        elif selection == 'c':
          abort = 1
          image_invert = invert_pic(filename)
        elif selection == 'd':
          abort = 1
          image_mirror = mirror_pic(filename)
        else:
          print('That is not a valid entry! Try again')
          print()

def blue_pic(filename):
    
    img = Image(Point(0,0), filename)
    height = img.getHeight()
    width = img.getWidth()
    for i in range (0, width):
      for j in range (0, height):
        colors = img.getPixel(i, j)
        Blue = colors[2]
        bluestring = color_rgb(0, 0, Blue)
        img.setPixel(i, j, bluestring)
    save_file(img) 

def grayscale_pic(filename):
    
    img = Image(Point(0,0), filename)
    height = img.getHeight()
    width = img.getWidth()
    for i in range (0, width):
      for j in range (0, height):
        colors = img.getPixel (i, j)
        Red = colors[0]
        Green = colors[1]
        Blue = colors[2]
        
        total_color_value = (Red + Green + Blue)
        neg_value = (total_color_value / 3)
        
        Red = Red - neg_value
        Green = Green - neg_value
        Blue = Blue - neg_value
        
        graystring = color_rgb(Red, Green, Blue)
        img.setPixel(i, j, graystring)
    save_file(img)

def invert_pic(filename):
    
    img = Image(Point(0,0), filename)
    height = img.getHeight()
    width = img.getWidth()
#    for i in range (0, width):
#      for j in range (0, height):
    
    save_file(img)

def mirror_pic(filename):
    
    img = Image(Point(0,0), filename)
    height = img.getHeight()
    width = img.getWidth()
#    for i in range (0, width):
#      for j in range (0, height):

    save_file(img)
    
def save_file(img):          
    file_save=input('Please enter the file you would like to save to: ')
    print()
    try:
      img.save(file_save)
    except:
      tk.TclError()
      print('The selected file cannot be saved to the file')
      sys.exit()

    
        
main()
Votes + Comments
DO NOT SHOUT
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.