×
Namespaces

Variants
Actions
Revision as of 02:56, 29 September 2009 by fasttrack (Talk | contribs)

Archived:How to edit an image in PySymbian

From Nokia Developer Wiki
Jump to: navigation, search
{{{width}}}
{{{width}}}


Article Metadata
Tested with
Devices(s): Nokia N96
CompatibilityArticle
Keywords: graphics, image
Created: (28 Mar 2008)
Last edited: fasttrack (29 Sep 2009)


Overview

This article describes how to manipulate images in PyS60.

code snippet

import appuifw, e32
from graphics import *
 
#Define the exit function:
app_lock=e32.Ao_lock()
def quit():app_lock.signal()
appuifw.app.exit_key_handler=quit
 
#We open the image
img=Image.open("C:\\i.jpg")
 
#We can see its current size
print img.size
 
#Now we resize it:
img=img.resize((240,240), keepaspect=0)
#The target size is a tuple containing the new dimensions in pixles
#keepaspect is optional. If 1, the image's current aspect ratio is maintained
 
#The image can also be transposed (here we rotate it by 90 degrees)
img=img.transpose(ROTATE_90)
#Other ways of transposing are:
#FLIP_LEFT_RIGHT, FLIP_TOP_BOTTOM, ROTATE_180, ROTATE_270
#Note that rotations are counterclockwise
 
#Finally, we save the new image
img.save("C:\\i2.jpg", quality=100)
 
#Tell the application not to close until the user tells it to:
app_lock.wait()

Postconditions

Here is the result for the example above:


InitialImg.jpg          FinalImg.jpg

The initial image                                                                                                               The resulting image


See also: How to add a text to an image

51 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×