954,541 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to get .jpg with python output

hi,
I am trying to get an image with my python application output.
please give me that process.

rajasekhar1242
Light Poster
27 posts since Dec 2008
Reputation Points: 10
Solved Threads: 1
 

Can you please post a smart question? You included no details about this "python application output" or anything about your program as it is. Then maybe I'll help.

shadwickman
Posting Pro in Training
497 posts since Jul 2007
Reputation Points: 186
Solved Threads: 77
 

Here is a Python output with an image:

# draw a flower with module turtle

import turtle as tu

tu.title('I call this one Flower')

# values for speed are 'fastest' (no delay), 'fast', (delay 5ms),
# 'normal' (delay 10ms), 'slow' (delay 15ms), and 'slowest' (delay 20ms)
tu.speed('fastest')

#turtle.color((.3,.5,.3))
tu.color('red')
tu.width(2)

radius = 180  # size of circle --> length of petal
extent = 70   # number of degrees in arc --> width of petal
angle = 0     # start out with a horizontal petal
x1 = 0        # location in X direction
y1 = -20      # location in Y direction

def flower():
    tu.up()
    tu.goto(x1,y1)
    tu.setheading(angle)
    tu.left(extent/2)
    tu.down()

    tu.circle(-radius, extent)
    tu.up()
    tu.goto(x1,y1)
    tu.down()
    tu.setheading(angle)
    tu.right(extent/2)
    # fills half the flower petal
    tu.begin_fill()
    tu.circle(radius, extent)
    tu.end_fill()

    tu.up()
    tu.goto(x1,y1)
    tu.setheading(angle)
    tu.down()

for angle in range(-45, 135, 45):
    radius = radius + 20
    flower()

for angle in range(135, 270, 45):
    radius = radius - 20
    flower()

tu.color('blue')
tu.up()
tu.goto(-60, -170)
tu.write("Fowers are beautiful!")

tu.up()
tu.setheading(90)
tu.goto(0, -15)

# keep showing until corner x is clicked
tu.done()
sneekula
Nearly a Posting Maven
2,427 posts since Oct 2006
Reputation Points: 961
Solved Threads: 212
 

Here is an example that actually creates a jpeg image file of your labor:

# drawing with PIL (Python Image Library)
# draw and save a small French flag (blue, white, red)

from PIL import Image, ImageDraw

# create a new 24x16 pixel image surface (default is black bg)
img = Image.new("RGB", (24, 16))

# set up the new image surface for drawing
draw = ImageDraw.Draw (img)

# draw a blue rectangle
# x1, y1 are upper left corner coordinates here
w = 8
h = 16
x1 = 0
y1 = 0
draw.polygon([(x1,y1),
(x1+w,y1), (x1+w,y1+h), (x1,y1+h)], fill='blue')

# draw a white rectangle
w = 8
h = 16
x1 = 8
y1 = 0
draw.polygon([(x1,y1),
(x1+w,y1), (x1+w,y1+h), (x1,y1+h)], fill='white')

# draw a red rectangle
w = 8
h = 16
x1 = 16
y1 = 0
draw.polygon([(x1,y1),
(x1+w,y1), (x1+w,y1+h), (x1,y1+h)], fill='red')

img.save("french_flag.jpg")

# optionally look at the image you have drawn
img.show()
sneekula
Nearly a Posting Maven
2,427 posts since Oct 2006
Reputation Points: 961
Solved Threads: 212
 

Thank you very much sneekula. I got some useful information from the code which you have sent to me. I understood some thing about PIL(Python Image Library).
But , i have developed a login screen by using Tkinter which has user name and password as text fields and one login button. After that i have developed some screens which are in navigation process. Now i want to place a particular logo which is a .jpg file on every screen top left corner. Is there any solution? Can we reach this target with this PIL module? Please give me a valuable reply..

rajasekhar1242
Light Poster
27 posts since Dec 2008
Reputation Points: 10
Solved Threads: 1
 

There should be some sort of static bitmap within Tkinter that you can place on these screens (if they are, in fact, Tkinter windows).

shadwickman
Posting Pro in Training
497 posts since Jul 2007
Reputation Points: 186
Solved Threads: 77
 

I am also using Pmw to develop my screens. is it possible to get .jpg with output...

rajasekhar1242
Light Poster
27 posts since Dec 2008
Reputation Points: 10
Solved Threads: 1
 

[QUOTE=sneekula;921987]Here is a Python output with an image:

# draw a flower with module turtle

import turtle as tu

tu.title('I call this one Flower')


heh heh, that's awesome. The doc page for the turtle module: http://docs.python.org/library/turtle.html

My C++ teacher had made a similar thing for Beginning programming called "Athlete"

zachabesh
Junior Poster
106 posts since Jun 2008
Reputation Points: 16
Solved Threads: 17
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You