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 – resizing


Let's now resize images by modifying their pixel dimensions and applying various filters for re-sampling.

  1. Download the file ImageResizeExample.bmp from the Packt website. We will use this as the reference file to create scaled images. The original dimensions of ImageResizeExample.bmp are 200 x 212 pixels.

  2. Write the following code in a file or in Python interpreter. Replace the inPath and outPath strings with the appropriate image path on your machine.

    1 import Image
    2 inPath = "C:\\images\\ImageResizeExample.jpg"
    3 img = Image.open(inPath)
    4 width , height = (160, 160)
    5 size = (width, height)
    6 foo = img.resize(size)
    7 foo.show()
    8 outPath = "C:\\images\\foo.jpg"
    9 foo.save(outPath)
  3. The image specified by the inPath will be resized and saved as the image specified by the outPath. Line 6 in the code snippet does the resizing job and finally we save the new image on line 9. You can see how the resized image looks by calling foo.show().

  4. Let's now specify the filter argument...