1,105,423 Community Members

Problem with PIL

Member Avatar
bomko
Newbie Poster
9 posts since Jul 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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

Member Avatar
Beat_Slayer
Posting Pro in Training
401 posts since Jun 2010
Reputation Points: 17 [?]
Q&As Helped to Solve: 105 [?]
Skill Endorsements: 1 [?]
 
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

Member Avatar
bomko
Newbie Poster
9 posts since Jul 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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)

Member Avatar
vegaseat
DaniWeb's Hypocrite
6,984 posts since Oct 2004
Reputation Points: 1,544 [?]
Q&As Helped to Solve: 1,872 [?]
Skill Endorsements: 67 [?]
Moderator
 
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)
Member Avatar
bomko
Newbie Poster
9 posts since Jul 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

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