Book Image

Python Multimedia

By : Ninad Sathaye
Book Image

Python Multimedia

By: Ninad Sathaye

Overview of this book

Multimedia applications are used by a range of industries to enhance the visual appeal of a product. This book will teach the reader how to perform multimedia processing using Python. This step-by-step guide gives you hands-on experience for developing exciting multimedia applications using Python. This book will help you to build applications for processing images, creating 2D animations and processing audio and video. Writing applications that work with images, videos, and other sensory effects is great. Not every application gets to make full use of audio/visual effects, but a certain amount of multimedia makes any application a lot more appealing. There are numerous multimedia libraries for which Python bindings are available. These libraries enable working with different kinds of media, such as images, audio, video, games, and so on. This book introduces the reader to the most widely used open source libraries through several exciting, real world projects. Popular multimedia frameworks and libraries such as GStreamer,Pyglet, QT Phonon, and Python Imaging library are used to develop various multimedia applications.
Table of Contents (13 chapters)
Python Multimedia Beginner's Guide
Credits
About the Author
About the Reviewers
Preface

Time for action – creating a new image containing some text


As already stated, it is often useful to generate an image containing only some text or a common shape. Such an image can then be pasted onto another image at a desired angle and location. We will now create an image with text that reads, "Not really a fancy text!"

  1. Write the following code in a Python source file:

    1 import Image
    2 import ImageDraw
    3 txt = "Not really a fancy text!"
    4 size = (150, 50)
    5 color = (0, 100, 0)
    6 img = Image.new('RGB', size, color)
    7 imgDrawer = ImageDraw.Draw(img)
    8 imgDrawer.text((5, 20), txt)9 img.show()
  2. Let's analyze the code line by line. The first two lines import the necessary modules from PIL. The variable txt is the text we want to include in the image. On line 7, the new image is created using Image.new. Here we specify the mode and size arguments. The optional color argument is specified as a tuple with RGB values pertaining to the "dark green" color.

  3. The ImageDraw module in PIL provides graphics...