How many times do we capture photos with our phones? Wouldn't it be great to customize these photos on the phones itself? This article illustrates an application which is useful for adding photo frame pattern on your selected photos. The code snippet is written with the simplest mobile application development tool, [[PyS60]]. The application has been tested on Nokia N73.
The application uses the following modules:
*appuifw moduleThe following functions are used to create this application PyPhotoFrame :
*graphics module
*e32 module
*time module
*draw_screen():draw the black screen on canvas
*save_image: save the image with its selected frame
*gold_frame():draw the gold frame on selected image
*sliver_frame(): draw the sliver frame on selected image
*wooden_frame(): draw the wooden frame on selected image
*red_frame(): draw the red frame on selected image
*blue_frame(): draw the blue frame on selected image
*RingsnChain(): draw the Rings and Chain frame on selected image
*DottedLine(): draw the Dotted line frame on selected image
*DottedLine(): draw the Big Dotted line frame on selected image
*BigDottedFrame(): draw the fancy4 frame on selected image
*ArrowFrame(): draw the arrow frame on selected image
All the functions and parameters are defined in source code in detail.
Code snippet
The code for the is below.
# importing the necessary modules
import e32
import appuifw
import graphics
import math
# defining color codes
BLACK=(0,0,0)
RED=(176,23,31)
BLUE=(0,178,238)
WHITE=(255,255,255)
DEEP_BLUE=(0,0,255)
VIOLET=(255,62,150)
GOLD=(205,133,0)
SLIVER=(139,137,137)
ORANGE=(139,90,0)
GRAY=(205,201,201)
WOOD= (139,87,66)
MEGENTA=(139,0,139)
CRIMSON=(220,20,60)
BLUE2=(0,0,238)
running=1
#global variables
global x,y
x=240
y=320
x1=25
Separator=10
outer_line=14
inner_line=5
x_Separator=10
y_Separator=20
def quit():'''the exit function'''
global running
running=0
app_lock.signal()
def menu_about():'''the about function'''
appuifw.note(u"PhotoFrame version 1.00" + "\n Developed by Nirpsis")
def handle_redraw(rect):'''function that will be called when the canvas needs to be redrawn'''
canvas.blit(img)
def draw_screen():'''define the draw
function - loads new image'''
#Global variable for application UI
global canvas
#Create an instance of Canvas and set it as the application's body
canvas = appuifw.Canvas(redraw_callback = handle_redraw,event_callback = None)
appuifw.app.body=canvas
#Set the screen to full
appuifw.app.screen = 'full'
appuifw.app.exit_key_handler=quit
#Global variable for application UI
global img
#We open the image
img=graphics.Image.open("C:\\image.jpg")
img=img.resize((240,320), keepaspect=0)
handle_redraw(img)
def save_image():'''save image'''
img.save("C:\\saved.jpg", quality=100)
appuifw.note(u"Image saved at C:\\saved.jpg")
def gold_frame():
'''function to draw golden frame'''
draw_screen()
img.rectangle((0,0,x,y),fill=None,outline=GOLD,width=20)
j=1
while (j<5):
img.rectangle(((Separator+(j*2)),(Separator+(j*2)),((x-y_Separator)+(j*2)),((y-y_Separator)+(j*2))),fill=None,outline=ORANGE)
j=j+1
handle_redraw(None)
def sliver_frame():
'''function to draw silver frame'''
draw_screen()
img.rectangle((0,0,x,y),fill=None,outline=GRAY,width=20)
j=1
while (j<5):img.rectangle(((Separator+(j*2)),(Separator+(j*2)),((x-20)+(j*2)),((y-20)+(j*2))),fill=None,outline=SLIVER)
j=j+1
handle_redraw(None)
def wooden_frame():
'''function to draw wooden frame'''
draw_screen()
img.rectangle((0,0,x,y),fill=None,outline=WOOD,width=20)
j=1
while (j<5):img.rectangle(((Separator+(j*2)),(Separator+(j*2)),((x-y_Separator)+(j*2)),((y-y_Separator)+(j*2))),fill=None,outline=WOOD)
j=j+1
handle_redraw(None)
def red_frame():
'''function to draw red frame'''
draw_screen()
img.rectangle((0,0,x,y),fill=None,outline=RED,width=20)
j=1
while (j<5):img.rectangle(((Separator+(j*2)),(Separator+(j*2)),((x-y_Separator)+(j*2)),((y-y_Separator)+(j*2))),fill=None,outline=RED)
j=j+1
handle_redraw(None)
def blue_frame():
'''function to draw blue frame'''
draw_screen()
img.rectangle((0,0,x,y),fill=None,outline=BLUE,width=20)
j=1
while (j<5):img.rectangle(((Separator+(j*2)),(Separator+(j*2)),((x-y_Separator)+(j*2)),((y-y_Separator)+(j*2))),fill=None,outline=WHITE)
j=j+1
handle_redraw(None)
def RingsnChain():
'''function to draw rings and chain frame '''
draw_screen()
img.rectangle((0,0,x,y),fill=None,outline=BLUE,width=5)
img.rectangle((20,20,220,300),fill=None,outline=BLUE,width=4)
a=1
while (a<23):>img.point(((Separator*a),Separator),fill=None,outline=DEEP_BLUE,width=8)
a=a+1
b=1
while (b<23):
global x,y,Separator
img.point(((Separator*b),(y-Separator)),fill=None,outline=DEEP_BLUE,width=8)
b=b+1
c=1
while (c<31):> img.point((Separator,(Separator*c)),fill=None,outline=DEEP_BLUE,width=8)
c=c+1
d=1
while (d<31):> global x,y,Separator
img.point(((x-Separator),(Separator*d)),fill=None,outline=DEEP_BLUE,width=8)
d=d+1
handle_redraw(None)
def DottedLine():
'''function to draw dotted line frame '''
draw_screen()
img.rectangle((0,0,x,y),fill=None,outline=MEGENTA,width=5)
img.rectangle((20,20,220,300),fill=None,outline=MEGENTA,width=4)
a=2
while(a<22):>
global x,y,x1,x_Separator,y_Separator
img.ellipse(((x_Separator*a),(x_Separator/2),((x_Separator*a)+5),x1),fill=None,outline=MEGENTA)
a=a+1
b=2
while (b<22):>
global x,y,x_Separator,y_Separator,x1
img.ellipse(((x_Separator*b),(y-x1),((x_Separator*b)+(x_Separator/2)),(y-(x_Separator/2))),fill=None,outline=MEGENTA)
b=b+1
c=1
while (c<19):>
global x,y,x_Separator,y_Separator,x1
img.ellipse(((x_Separator/2),(x_Separator+(c*15)),y_Separator,(x1+(c*15))),fill=None,outline=MEGENTA)
c=c+1
d=1
while (d<19):>
global x,y,x_Separator,x1
img.ellipse(((x-y_Separator),(x_Separator+(d*15)),(x-(x_Separator/2)),(x1+(d*15))),fill=None,outline=MEGENTA)
d=d+1
handle_redraw(None)
def DottedLine():
'''function to draw dotted line frame '''
draw_screen()
img.rectangle((0,0,x,y),fill=None,outline=CRIMSON,width=5)
img.rectangle((20,20,220,300),fill=None,outline=CRIMSON,width=4)
a=0
while (a<11):>
global x,y,x1,x_Separator,y_Separatorb=0
img.ellipse(((x_Separator+(a*y_Separator)),x_Separator,(x1+(a*y_Separator)),(y_Separator-(x_Separator/2))),fill=CRIMSON,outline=GRAY)
a=a+1
while (b<11):>
global x,y,x_Separator,y_Separator,x1
img.ellipse(((x_Separator+(b*y_Separator)),(y-(x1-x_Separator)),(x1+(b*y_Separator)),(y-x_Separator)),fill=CRIMSON,outline=GRAY)
b=b+1
c=0
while (c<15):>global x,y,x_Separator,y_Separator,x1
img.ellipse((x_Separator,(x_Separator+(c*y_Separator)),(x1-x_Separator),(x1+(c*y_Separator))),fill=CRIMSON,outline=GRAY)
c=c+1
d=0
while (d<(x_Separator+5)):global x,y,x_Separator,x1
img.ellipse(((x-15),(x_Separator+(d*y_Separator)),(x-x_Separator),(x1+(d*y_Separator))),fill=CRIMSON,outline=GRAY)
d=d+1
handle_redraw(None)
def BigDottedFrame():
'''function to draw big dotted frame '''
draw_screen()
x1=25
img.rectangle((0,0,x,y),fill=None,outline=VIOLET,width=4)
img.rectangle((20,20,220,300),fill=None,outline=VIOLET,width=2)
a=0
while (a<22):>global x,y,x1,x_Separator,y_Separator
img.ellipse(((x_Separator+(a*x_Separator)),(x_Separator/2),(x1+(a*x_Separator)),(x1-x_Separator)),fill=VIOLET,outline=GRAY)
a=a+1
b=0
while (b<22):>img.ellipse(((x_Separator+(b*x_Separator)),(y-(x1-x_Separator)),(x1+(b*x_Separator)),(y-5)),fill=VIOLET,outline=GRAY)
b=b+1
c=0
while (c<30):>global x,y,x_Separator,y_Separator,x1
img.ellipse(((x_Separator/2),(x_Separator+(c*x_Separator)),(x1-x_Separator),(x1+(c*x_Separator))),fill=VIOLET,outline=GRAY)
c=c+1
d=0
while (d<30):>global x,y,x_Separator,x1
img.ellipse(((x-(x1-x_Separator)),(x_Separator+(d*x_Separator)),(x-5),(x1+(d*x_Separator))),fill=VIOLET,outline=GRAY)
d=d+1
handle_redraw(None)
def ArrowFrame():
'''function to draw arrow frame '''
draw_screen()
x1=25
img.rectangle((0,0,x,y),fill=None,outline=BLUE2,width=4)
img.rectangle((20,20,220,300),fill=None,outline=BLUE2,width=2)
a=0
while (a<13):>global x,y,x1,x_Separator,y_Separator
img.ellipse(((x_Separator+(a*(y_Separator-3))),(x_Separator/2),(x1+(a*(y_Separator-3))),y_Separator),fill=BLUE2,outline=WHITE)
a=a+1
b=0
while (b<13):>global x,y,x_Separator,y_Separator,x1
img.ellipse(((x_Separator+(b*(y_Separator-3))),(y-(x1-x_Separator)),(x1+(b*(y_Separator-3))),y),fill=BLUE2,outline=WHITE)
b=b+1
c=0
while (c<18):>global x,y,x_Separator,y_Separator,x1
img.ellipse(((x_Separator/2),(x_Separator+(c*(y_Separator-3))),y_Separator,(x1+(c*(y_Separator-3)))),fill=BLUE2,outline=WHITE)
c=c+1
d=0
while (d<18):>global x,y,x_Separator,x1
img.ellipse(((x-y_Separator),(x_Separator+(d*(y_Separator-3))),(x-5),(x1+(d*(y_Separator-3)))),fill=BLUE2,outline=WHITE)
d=d+1
handle_redraw(None)
# Create options menu
appuifw.app.menu = [(u"Load Image", draw_screen),(u"Simple",((u"Golden",gold_frame),(u"Sliver",sliver_frame),(u"Wooden",wooden_frame),(u"Red",red_frame),(u"Blue",blue_frame))),(u"Fancy",((u"Rings n Chain",RingsnChain),(u"Dotted line",DottedLine),(u"Dotted Line",DottedLine),(u"Big Dotted",BigDottedFrame),(u"Arrow",ArrowFrame))),(u"Save Image",save_image),(u"About",menu_about),(u"Exit",quit)]
draw_screen()
app_lock = e32.Ao_lock()
#Wait for the user to request the exit
app_lock.wait()
Screenshots


0 comments:
Post a Comment