file io - Getting Width and Height of an Inputted Picture in Python -
our assignment input picture , create program writes program draw picture in python 2.7.5. here code:
from pygame import * infile = open("picture.jpg") out = open('fa3.py','w') width = infile.get_width() height = infile.get_height() out.write(''' pygame import * screen=display.set_mode((800,600)) running=true while running: evt in event.get(): if evt.type == quit: running = false ''') in range(width,height): c = infile.get_at() out.write('''draw.cricle(screen,(c),x,y,2)''')
i having trouble getting height , width of file , finding each individual pixel location in image. teacher told me use ".get_width , height" not seem work. know x,y not defined each pixel location inserted. appreciated. thanks.
the pil image module able want.
http://effbot.org/imagingbook/image.htm
example show image
from pil import image im = image.open("bride.jpg") im.show()
the following additional code let manipulate pixels (as long save after)
pixels = im.load() print pixels[x, y] pixels[x, y] = value #value tuple in format (normally) (235,154,124) or (red,green,blue)
to image size
im.size() #width , height, (400,600) im.size[0] #width, 400 im.size[1] #height, 600
Comments
Post a Comment