1.11M Members

Problem with PIL

 
0
 
from PIL import Image, ImageDraw
from random import randint
picture = Image.new("RGB", (600, 600))
artist = ImageDraw.Draw(picture)

for i in range(100):
    x1, y1 = randint(0, 600), randint(0, 600)
    x2, y2 = randint(0,600), randint(0,600)
    color = (randint(0, 255), randint(0, 255), randint(0, 255))
    width = randint(2, 20)
    artist.line([x1, y1, x2, y2], color, width)
#picture.convert("RGB")
picture.show()

i've made this program just to demonstrate my problem. The thing is that when i run this program Windows Photo Viewer opens up but theres no image just this message:

WPM can't open this picture because either the picture is deleted, or it's in a location that isnt available

Now i'm using python 2.7 and W7 and i would really apreciate help because i cannot program further because i cannot see the result

 
0
 

I don't get it????

Whats the question? You create a picture image object RGB 600 by 600, but you write no data to it.

And you do something with a ImageDraw object but I can't see what also.

Cheers and Happy coding

 
0
 

i've forgot to change all the names before reposting it here.

artist = ImageDraw.Draw(picture)

now with this error resolved the program should make a picture with 100 diffret lines. well it doesnt open it to me and i would like to know why? Or is it still problem in the code that i do not get the right result (picture with 100 diffrent lines)

 
1
 

The PIL show() function internally saves a temporary bitmap file, then calls the default viewer to show it. Looks like your default viewer does not accept command line image files. You can use module webbrowser instead ...

from PIL import Image, ImageDraw
from random import randint

picture = Image.new("RGB", (600, 600))
artist = ImageDraw.Draw(picture)

for i in range(100):
    x1, y1 = randint(0, 600), randint(0, 600)
    x2, y2 = randint(0,600), randint(0,600)
    color = (randint(0, 255), randint(0, 255), randint(0, 255))
    width = randint(2, 20)
    artist.line([x1, y1, x2, y2], color, width)

#picture.convert("RGB")
#picture.show()
# save the image to show it with the web browser's viewer
filename = "aa_image.jpg"
picture.save(filename)
import webbrowser
webbrowser.open(filename)
 
0
 

thank you very much, it works just fine now:)

Question Answered as of 3 Years Ago by vegaseat and Beat_Slayer
You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article