Python
  Home arrow Python arrow Imagine Python
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
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? 
Google.com  
PYTHON

Imagine Python
By: Mark Lee Smith
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 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:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log 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


    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

    - Tuples and Other Python Object Types
    - The Dictionary Python Object Type
    - String and List Python Object Types
    - Introducing Python Object Types
    - Mobile Programming using PyS60: Advanced UI ...
    - Nested Functions in Python
    - Python Parameters, Functions and Arguments
    - Python Statements and Functions
    - Statements and Iterators in Python
    - Sequences and Sets in Python
    - Python Expressions and Operators
    - Dictionaries, Variables and Statements in Py...
    - Data Types in Python
    - The Python Language
    - SSH with Twisted





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek