Python
  Home arrow Python arrow Imagine Python
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PYTHON

Imagine Python
By: Mark Lee Smith
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 50
    2004-05-03

    Table of Contents:
  • Imagine Python
  • Batch Processing
  • Image.Show
  • Lock It Down

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    Route your faxes to your email inbox. Private, secure fax numbers available from CallWave. Choose your fax number.

    Imagine Python
    (Page 1 of 4 )

    Quite a cryptic title, but if you haven’t guessed, were talking about Images. This being a Python article that’s what we're using! If you’ve never thought about it, or -- even better -- if you didn’t know it was possible then you’re in for a nice surprise; not only can Python do this but it’s pretty good at it, too. Actually, Python works well with graphics in general, but for now we’re sticking to the 2D kind.

    Why would anyone want to do this with a language like Python?

    Fortunately this is not a question I've had to ask myself since the answer seems pretty obvious to me. But basically that's what this article is all about. Over the next few pages we'll be looking at some of the different places you could use Python to automate and generally play with your images.

    You will need to have at least basic knowledge of these subjects, so if you're new to Python you should probably read Vikram Vaswani's "Python 101" first and come back later!

    Essentially when you do anything to an image what you're actually doing is writing/moving bytes around. You can do this manually, but when you have an excellent third party module like PIL (Python Imaging Library), why bother?

    So let's add a little extra image processing power to Python! You can get the latest version of PIL from www.pythonware.com

    Windows users should download the windows installer (.exe). Those installing PIL from source should probably take a look through "Installing Python Modules" in the Python docs, if only out of interest.

    On to the Fun Stuff

    Ok, now that we have the "basics" out of the way, it's time for the fun stuff! Something like converting a JPEG image to a GIF maybe. In most cases all you should have to do is open the image and save it with a different file extension and PIL will do the rest!


    >>> import Image
    >>> image Image.open('sample.jpg')
    >>> image.save('sample.gif')
    >>>

    If this didn't work for you, don't worry; chances are all you have to do is add another line before saving.
     


    >>> import Image
    >>> image Image.open('sample.jpg')
    >>> image.convert('RGB')
    >>> image.save('sample.gif')
    >>>

    More Python Articles
    More By Mark Lee Smith


     

       

    PYTHON ARTICLES

    - SSH with Twisted
    - Mobile Programming in Python using PyS60: UI...
    - Python: Count on It
    - Python Strings: Spinning Yarns
    - Python: More Fun with Strings
    - Python: Stringing You Along
    - Python Operators
    - Bluetooth Programming in Python: Network Pro...
    - Python Sets
    - Python Conditionals, Lists, Dictionaries, an...
    - Python: Input and Variables
    - Introduction to Python Programming
    - Mobile Programming in Python using PyS60: Ge...
    - Bluetooth Programming using Python
    - Finishing the PyMailGUI Client: User Help To...

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway