Introduction to Image Operations in Python
Image manipulation is an interesting subject, as well almost inevitable in today's websites, you can use it to render CAPTCHA, crop & resize images, convert between image formats and many more advanced functions. Python with it's growing popularity has encouraged the community & enterprises to come up with modules for image processing in Python, there are many available modules in Python which will help you manipulate images, but in this article we'll be looking into the Python Imaging Library developed by pythonware.com. PIL is able to read a large number of image formats, but it has been restricted to writing out to only the popular formats.
Get the latest stable version of PIL from http://www.pythonware.com/products/pil/. Make sure you have Python development files on your system, in case you installed a Python binary. Untar & run python setup.py install, in case you run into any problem or you would like to customize your installation please refer to the README.
By basic usage I mean opening an image, identifying the format, creating thumbnail, writing out in a different format than the source, etc. I can explain the functions but that is already done in the PIL documentation, so like always let me help you understand using a demo program with comments at appropriate places.
There are a wide variety of advanced functions available in PIL, but it is out of the scope of this article to cover all the functions, so here we'll be looking into some popular operations like crop, image transform etc. Please follow the code sample below:
The PIL has many sub-modules which offer more extended functionality ImageFont, ImageEnhance, ImageDraw and so on, for a full list and documentation please refer to the PIL documentation.
Re: Introduction to Image Operations in Python
This is really good tut! I haven't found better even on whole internet than this one. Appreciate it.
|All times are GMT +5.5. The time now is 09:07.|