Tag Archives: Python

How to Watermark Your Photos with Python

When you look up photos online, you will notice that some of them are watermarked. A watermark is usually some text or a logo overlaid on the photo that identifies who took the photo or who owns the rights to the photo. Some professionals recommend adding watermarks to your photos before sharing them on social media to prevent other people from using your photos as their own and profiting off your work. Of course, watermarking can be removed fairly easily, so this isn’t as useful as it used to be as a digital rights tool.

Anyway, the Pillow package provides the tools you need to add watermarks to your photos! The first thing you need to do is install Pillow if you haven’t already:


pip install pillow

Once that’s installed, we can continue! Continue reading How to Watermark Your Photos with Python

PyDev of the Week: Bruno Oliveira

This week we welcome Bruno Oliveira (@nicoddemus) as our PyDev of the Week! Bruno is a core developer of the pytest package, a 3rd party Python package created for writing unit tests. You can check out some of his work over on Github. Bruno also has a small blog with some articles on Python. Let’s take some time to get to know Bruno!

Can you tell us a little about yourself (hobbies, education, etc):

About my education, I’m a Computer Science bachelor through the Federal University of Santa Catarina, in Florianopolis (southern Brazil). When I was young, I loved drawing and planned to become an architect after my godfather, but discovered programming (with Delphi!) when I was 14 and never wanted to be anything else.

As for hobbies, I mostly enjoy computer games being a huge Dark Souls fan.

I work as a technical lead at ESSS, where we develop engineering applications using Python, C++ and to a lesser degree JavaScript. Continue reading PyDev of the Week: Bruno Oliveira

How to Resize a Photo with Python

Sometimes you will find yourself wanting to resize a photo. I usually want to do this for photos that I want to email or post on a website since some of my images can be quite large. Normal people use an image editor. I usually do as well, but for fun I thought I would look into how to do it with the Python programming language.

The quickest way to do this is to use the Pillow package which you can install with pip. Once you have it, open up your favorite code editor and try the following code:

from PIL import Image
 
def resize_image(input_image_path,
                 output_image_path,
                 size):
    original_image = Image.open(input_image_path)
    width, height = original_image.size
    print('The original image size is {wide} wide x {height} '
          'high'.format(wide=width, height=height))
 
    resized_image = original_image.resize(size)
    width, height = resized_image.size
    print('The resized image size is {wide} wide x {height} '
          'high'.format(wide=width, height=height))
    resized_image.show()
    resized_image.save(output_image_path)
 
if __name__ == '__main__':
    resize_image(input_image_path='caterpillar.jpg',
                 output_image_path='caterpillar_small.jpg',
                 size=(800, 400))

Continue reading How to Resize a Photo with Python

Convert a Photo to Black and White in Python

Black and white images aren’t for everyone. I personally like to play around with them as you can sometimes take a boring photo and turn it into something dramatic. I have also rescued a drab photo by turning it black and white. If you want to change a photo that you took into a black and white photo programmatically, the Pillow package has you covered. In this article we will look at the two simple ways to convert a photo to black and white and then we will also learn how to make a sepia-toned photo.


Making it Black and White

The first obstacle is finding a photo that you would like to edit. For this example, we will use the following fuzzy caterpillar: Continue reading Convert a Photo to Black and White in Python

PyDev of the Week: Giampaolo Rodola’

This week we welcome Giampaolo Rodola’ (@grodola) as our PyDev of the Week! Giampaolo is the creator and maintainer of the psutil project as well as the pyftpdlib and pysendfile packages. He is also been a core developer and maintainer of ftplib, asyncore and asynchat stdlib modules. You can check out some of his work over on Github or check out his blog! Let’s take some time to get to know our fellow Pythonista better!

Can you tell us a little about yourself (hobbies, education, etc):

I am a Python freelancer working remotely. I am Italian and I am currently based in Prague. My main hobby is programming and I also enjoy playing guitar, singing and astronomy. I also enjoy traveling and have been semi-nomadic for the last 3.5 years. As such I may also work and travel at the same time, although if I get a long gig I prefer to stay in Prague. I have no formal IT education. I learned programming because it was fun and I ended up paying the rent with it by accident. Continue reading PyDev of the Week: Giampaolo Rodola’

How to Crop a Photo with Python

If you like taking photos than you will probably also find yourself cropping your photos from time to time. I will crop photos to get rid of background noise or to just focus more on the subject I was trying to capture. I also like to take high resolution photos of insects or other small creatures and then crop it down to make it seem like I was even closer to the insect than I really was.

Now most people will use a photo editing application to crop their image, such as Photoshop Elements. I use these kinds of tools too, but you can also use the Python programming language to do the cropping for you. One good example where you might want to use Python is if you have thousands of scanned images of the same type, then it makes more sense to just write a script to do the cropping for you.

The most popular package for image manipulation in Python is the Pillow package, a “Friendly fork of the Python Imaging Library (PIL)”. You can install Pillow using pip: Continue reading How to Crop a Photo with Python

PyDev of the Week: Tom Augspurger

This week we welcome Tom Augspurger (@TomAugspurger) as our PyDev of the Week! Tom is a core developer of the pandas, dask and distributed Python packages. You can see what Tom is up to by checking out his blog or over on Github. Let’s spend some time getting to know Tom better!

Can you tell us a little about yourself (hobbies, education, etc):

I became interested in the financial crises that rolled through the world in 2008. This pushed me into studying economics, to try to figure out what was going on and how to fix it. I went on to study economics in graduate school at the University of Iowa. It took me 3 years to realize that I wasn’t suited for a PhD, so I left the program early with a masters.

My hobbies used to revolve around data analysis and contributing to open source projects. Since having a son last year, raising him has become my one and only hobby 🙂 Continue reading PyDev of the Week: Tom Augspurger

Anaconda and Microsoft Partner for Machine Learning

Anaconda released a statement that they are partnering with Microsoft to “deliver Python-powered machine learning”. Anaconda is a data science distribution of the Python programming language. If you go check out the statement, you will find that Microsoft is specifically planning to “embed Anaconda into Azure Machine Learning, Visual Studio and SQL Server”.

I used to use Python for system administration on Windows desktops and servers and this sounds pretty exciting to me. I liked the PyWin32 package, but if I had had a native Python implementation in SQL Server, that would have been awesome!

The Python Reddit community seems to be cautiously optimistic about this partnership.

Overall, I believe this will be a good thing for Python as a whole and Python in the data science community specifically.

wxPython: All About Accelerators

The wxPython toolkit supports using keyboard shortcuts via the concept of Accelerators and Accelerator Tables. You can also bind directly to key presses, but in a lot of cases, you will want to go with Accelerators. The accelerator gives to the ability to add a keyboard shortcut to your application, such as the ubiquitous “CTRL+S” that most applications use for saving a file. As long as your application has focus, this keyboard shortcut can be added trivially.

Note that you will normally add an accelerator table to your wx.Frame instance. If you happen to have multiple frames in your application, then you may need to add an accelerator table to multiple frames depending on your design.

Let’s take a look at a simple example: Continue reading wxPython: All About Accelerators