User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 425,861 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,528 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Python advertiser: Programming Forums
Jan 22nd, 2005
Views: 3,034
This is an application of the Python Image Library (PIL) and shows you how simple it is to do pixel math on an image.
python Syntax | 4 stars
  1. # do pixel math on an image using the PIL image library
  2. # free from: http://www.pythonware.com/products/pil/index.htm
  3. # Python23 tested vegaseat 22jan2005
  4.  
  5. import Image
  6.  
  7. # open an image file (.jpg or.png) you have in the working folder
  8. im1 = Image.open("Audi.jpg")
  9.  
  10. # multiply each pixel by 0.9 (makes the image darker)
  11. # works best with .jpg and .png files, darker < 1.0 < lighter
  12. # (.bmp and .gif files give goofy results)
  13. # note that lambda is akin to a one-line function
  14. im2 = im1.point(lambda p: p * 0.9)
  15.  
  16. # brings up the modified image in a viewer, simply saves the image as
  17. # a bitmap to a temporary file and calls viewer associated with .bmp
  18. # make certain you have associated an image viewer with this file type
  19. im2.show()
  20.  
  21. # save modified image to working folder as Audi2.jpg
  22. im2.save("Audi2.jpg")
Comments (Newest First)
vegaseat | Kickbutt Moderator | May 20th, 2005
The Python Image Library (PIL) is now available for Python24.
Download and instal
PIL-1.1.5.win32-py2.4.exe [533k]
from
http://effbot.org/downloads/#imaging
vegaseat | Kickbutt Moderator | Mar 20th, 2005
At this point PIL is only available for Python v2.3, sorry! I hope this will change soon.
vegaseat | Kickbutt Moderator | Jan 22nd, 2005
I am using Python23 and the PythonWin IDE from
http://starship.python.net/crew/mhammond/win32/
all free downloads and simple to use.
Post Comment

Only community members can submit or comment on code snippets. You must register or log in to contribute.

DaniWeb Marketplace (Sponsored Links)
All times are GMT -4. The time now is 5:46 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC