I am trying to return True or False
by comparing dimension size(width and heights) of two pictures.
so i came up with
import media

f = media.choose_file()
pic = media.load_picture(f)

g = media.choose_file()
pic1 = media.load_picture(g)

x = pic.get_width() * pic.get_height()
y = pic1.get_width() * pic1.get_height()

but i have no idea return these valuse to true and false(bool).

Also, i have another thing to solve,

Return a new 20 pixel by 20 pixel Picture that has a white background, a black 16 by 16 oval at position (0, 0), and a black letter C (uppercase) at position (6, 3).

For this one i came up with,

pic = media.create_picture(20, 20)

i know that i have to use media.add_oval and media.add_text function
but i have no idea how to.
plz help me out here.

Recommended Answers

All 5 Replies

So it looks like you are writing a function to see if the areas of the pictures are the same? (x is the area of pic, and y is the area of pic1)

Simply end your function with

return(x==y)

This will return True or False.

what about the second one?
oh
actually im not comparing the area, im comparing each size.

In that case there is no need to calculate the area.

Instead, just compare the dimensions. Something like:

return (pic.get_width() == pic1.get_width()) and (pic.get_height() == pic1.get_height())

CAn you please help me with media.add_oval and media.add_text functions to
return a new 20 pixel by 20 pixel Picture that has a white background, a black 16 by 16 oval at position (0, 0), and a black letter C (uppercase) at position (6, 3)?

Ok, so I've looked over your assignment, and I've come up with this. I don't know if it really helps you, but here goes.

'''
Created on Feb 15, 2012

@author: sin
'''
import Image, ImageDraw #As a first thing, you must have the third party graphics libraries.
#You can easily download them off of http://www.pythonware.com/products/pil/

def circleplusc():# Defining the new function
    img = Image.new("RGB", (20, 20), "#FFFFFF") #Creating the new imagine, with the 20x20 pixels.
    draw = ImageDraw.Draw(img) # We assign the function imagedraw.draw(img) to a value draw, for an easy use up ahead.

    r, g, b = 0, 0, 0 # Assigning colors to the rgb values, r=0, g=0, b=0, meaning r=red, g=green, b=blue
    r1, g1, b1 = 255, 255, 255 #Same as above.
    draw.ellipse((0, 0, 16, 16), fill=(int(r), int(g), int(b))) #We draw the ellipse, oval, circle, depending on the coordinates.
    draw.text((6, 3), "C", fill=(int(r1), int(g1), int(b1)))# We draw the text, literally... having as colors the opposite of the elipse. 

    img.save("circleplusc.png", "PNG") # We save the imagine as a PNG.
if __name__ == "__main__":
    circleplusc() #We run the function.

#Tested with Python 2.7.2 interpretor, I personally use Eclipse for a better use on Python, but still, tested with Python also.
#The output is a PNG image, of a 20x20 pixels, with a black circle, and nearly its center a white C
#Tested and completed Feb 15, 2012 by sin.

Please report me any bugs, or errors, as I myself i'm a n00b @ Python, and still learning.:D
Hope I helped.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.