Using the Pillow deform function

Photo by Dan DeAlmeida on Unsplash

You can use the Pillow ImageOps deform function to apply general deformations to an image. Typical deformations include:

  • Barrel distortion. This happens when an image appears more magnified at its centre than its edges. It is sometimes called a fisheye effect.

You can use the deform function to correct for these types of distortion in a photograph. You can also…


Stop wasting time trying to manually install those difficult modules.

Photo by Susan Q Yin on Unsplash

Python is great, made better by the extensive infrastructure provided by open-source modules.

What isn’t always so great is installing all the modules you need, and making sure they are all mutually compatible with your version of Python and with each other.

With many modules, you might need a different version depending on the version of Python you are using, and maybe also on your operating system (Windows, Mac, and different flavours of Linux might each require a different version of some modules). …


In this article we will see how to create Voronoi diagrams in Python, using Scipy and generativepy.

What are Voronoi diagrams?

This image shows a set of seed points. We have placed the seed points randomly, but you could place the points according to some pattern if you prefer.


Catch errors and handle them in your app.

Photo by Sigmund on Unsplash

In this article we will look at exceptions:

  • Program errors.

This article is taken from my book Python Quick Start.

Program errors

Computer programs sometimes go wrong. There are three broad types of error you will encounter when you are writing code:

  • Syntax errors.

Syntax errors occur when the code you type in isn’t valid. This is often due to typing errors or misunderstanding Python syntax. For example:

s = [1, 2, 3…


Optimize list and string manipulation using slice notation.

Photo by freestocks on Unsplash

Slicing allows us to access part of a list or other sequence. In this article we will see how to:

  • Specify a slice of a list.

This article is from my book Python Quick Start.

Slicing a list

We already know how to obtain a list element by indexing:

k = [10, 20, 30, 40, 50]
print(k[1]) # 20

Of course, k[1] references element number 1 of list k, which is the second element because elements are numbered…


Making your plots zing.

Photo by Aswin Anand on Unsplash

Matplotlib allows you to control many aspect of your graphs. In this article we will see how to style line plots. This includes

  • Controlling the colour, thickness and style (solid, dashed, dotted etc) of the lines.

You can choose to plot data points using lines, or markers, or both.

Matplotlib has a simple notation to set the colour, line style and marker style using a coded text string, for example ‘r:’ creates a red, dottedline. …


OSS for fun and profit

Photo by Chris Barbalis on Unsplash

This article is a quick guide on how to create and run your own open-source project. Specifically, it assumes it will be a Python project, although many of the things covered here can be applied to other types of project.

This isn’t a guide on how to set up a GitHub account and commit your first source files. Instead, it focusses on the wider whys and hows of open source development, and will hopefully help you to avoid the common pitfalls.

Why do it?

People create open-source software for many different reasons.

Quite often, a developer will decide to create a piece of…


What I learned from writing three Python books in a year

Photo by Eugenio Mazzone on Unsplash

Over the past year or so, I have written three e-books on various topics in Python programming. Although I certainly don’t consider myself to be an expert on self-publishing, I have learned a bit in this time, so I will share it here. I hope you might find it useful.

This article covers four stages:

  • Choosing and researching the topic.

I have found the whole process takes me about 3 months, if I put most of my hobby time…


Process images in 3 lines of Python

Pillow is a versatile and popular Python imaging library. The ImageEnhance module is a particularly useful module within Pillow. It can be used to adjust colour, contrast, brightness and sharpness in a few simple lines of code.

_Enhance interface

Each image enhance function is implemented as an object that implements the _Enhance interface. The interface provides a single method:

enhance(factor)

For example, the ImageEnhance.Brightness class controls the brightness of an image, It has an enhance method that it inherits from _Enhance.

factor is a number that controls the effect. For example, for Brightness a factor


Easy animation with generativepy

Photo by Gensa Hub on Unsplash

generativepy makes it very easy to create animated GIFs. This can be done with a simple script, and usually results in a fairly well optimised GIf file.

The gif module makes use of the gifsicle application. This can be downloaded for free, and must be installed on your system in order for the gif module to work.

GIF images

GIF (Graphics Interchange Format) is a bitmap image format that was developed in the 1980s for transferring images over networks. …

Martin McBride

Software developer. Java, Python, C++ etc. I write for pythoninformer.com and maintain the generativepy library.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store