Automate Graphic Design using Python

Use Python Pillow to automate the creation of a hundred warehouse labels for the signage of picking locations.

Samir Saci
Towards Data Science

--

(Image by Author)

Have you ever wished that designing labels and posters could be as easy as coding a script?

With Python, it can be!

In this article, we’ll show you how to use Pillow, a popular Python library for image processing, to automate the creation of hundreds of warehouse labels with just a few lines of code.

Scenario

You are an implementation manager in the logistics department of an international fashion retailer.

For each project, you manage the implementation of the equipment, train the teams and design the layouts of storage locations.

Warehouse Label Automatically Designed with Python Pillow
Example of Warehouse Label — (Image by Author)

Therefore, you spend a tremendous time in graphic design for posters, security signage or labels.

In this article, we explore a method to automate the process of graphic design using the Python library Pillow.

💌 New articles straight in your inbox for free: Newsletter
📘 Boost your Productivity with Data Analytics: Productivity Cheat Sheet

If you prefer watching, have a look a the YouTube tutorial

I. How to do graphic design with Python?

1. Scenario

You are part of the project team of the logistics department of a fashion retailer that has warehouses on all continents.

This team is in charge of implementing processes and equipment for newly opened distribution centres.

Example of Distribution Center that needs labels that can be designed with python
Example of a Distribution Center — (Image by Author)

For instance, your major task is to design the layout of racks for storage locations.

In a warehouse, you can have several hundred locations with pallets/shelves for storage and picking.

Examples of Racks with pallets for which we use pallets
(Ground Level: Picking Locations, Other Levels: Storage) — (Image by Author)

In order to help the operators to find the right locations, you need to print and stick labels with key information.

Example of the label for an elevated storage location — (Image by Author)

2. Objective

You want to design customized labels to reduce errors, help operators and respect the standard operating procedures of your company.

Because you may have several thousand locations per warehouse, you would like to automate this process.

3. Solution

I will present a solution to automatically create these labels.

Final Results of labels — (Image by Author)

It is a simple Python script that imports location information from an Excel file and automatically generates labels like the ones above.

💡 Follow me on Medium for more articles related to 🏭 Supply Chain Analytics, 🌳 Sustainability and 🕜 Productivity.

II. Label Design

1. Six key parameters

This label will be read by three types of operators:

  • Reach Truck Drivers who will put pallets or boxes in these locations
  • Picking Operators that will take items from these locations
  • Inventory admins that will perform inventory counts
Label information automatically placed using python pillow
Label Information — (Image by Author)

Therefore, you will need to include some key information related to the location and the product stored:

  • A coloured arrow to show where the product is stored (above or below)
  • A bar code with the SKU code for the operators using an RF gun
  • The picking location number with the alley, cell and level numbers
  • Three Icons that provide information related to the location and the item stored

2. Spatial Coordinates

Considering the size of each item, you want to fix the spatial coordinate of each item.

Coordinates of the items placed on the label using Python Pillow
Key Coordinates — (Image by Author)

In this very simple label, you have 5 parameters to locate the different items.

We decided to put the origin in the top-left corner; it’s because Pillow is using the same origin.

3. Import PNG icons

The storage location number and the bar code will be generated in your Python script.

Import png icons in your label using python pillow
Icons to add — (Image by Author)

The other items are icons that will be imported into your Pillow object using locally stored png files.

4. Information source

In your master data, you have several thousand SKUs with information like the size, weight, price etc.

You will allocate each of these SKUs to a picking location that will require a specific label.

For your automation tool, you can create an Excel file with a line for each SKU including

  • SKU Code: that will be used to create the bar code
  • Geographical information: alley, zone and location number
  • Logistics handling unit: pieces if you take items piece by piece or Carton if you take the item by carton
  • Arrow type with the direction and the colour
  • Product Category (Tie, Shoes, Dress, …)
  • Picking Location Special Information: dangerous goods, sprinklers, RFID, …

III. Automate the label creation with Python Pillow

1. Loop Through Your Data Frame using Pandas

Your script will loop through the lines of your data frame to generate one label for each line.

For each label, you start by creating a blank canvas with a black border and specific dimensions (500, 200) in pixels.

Blank rectangle used as a canvas to design your label with Python pillow
Blank Canvas — (Image by Author)

2. Add Icons to the Label using Pillow

For this step, you will add icons specifying

  • Coordinates (x, y)
  • Dimensions after resizing using percentage
  • Icon filename is taken from the data frame

P.S:

  • You need to convert your png files to keep a transparent background.
  • Icons coordinates are defined using their size on both axes
Labels with png icons added using python pillow
Label with icons — (Image by Author)

3. Generate a Barcode for the SKU Code with EAN13 library

The bar code is generated using the SKU code and the barcode library of python.

P.S:

  • create_ean will generate a png file stored locally that will be used in the loop
  • The bar code has been resized to fit in the canvas
Label with bar code — (Image by Author)

4. Add the Location Code to the Label with Pillow

This last step will be fully performed using Python Pillow.

Warehouse Label Automatically Designed with Python Pillow
Final Result — (Image by Author)

VI. Conclusion

1. You have an automated solution of label design

Your labels are generated and ready to be printed.

Say goodbye to time-consuming graphic design tasks and hello to automation with Python Pillow.

This is not an artwork of Leonardo Da Vinci but it can be automatically generated for thousand labels with just a click.

Animated GIF of labels automatically created with Python Pillow
1000 labels generated in 30 seconds — (Image by Author)

If you want to learn about more advanced functionalities of Pillow, you can have a look at their official documentation.

2. Go Beyond and Automate your PowerPoint Slides Creation

If you believe that making PowerPoint presentations is boring, have a look at the article below,

About Me

Let’s connect on Linkedin and Twitter, I am a Supply Chain Engineer using data analytics to improve logistics operations and reduce costs.

If you are interested in Data Analytics and Supply Chain, have a look at my website

--

--

Top Supply Chain Analytics Writer — Follow my journey using Data Science for Supply Chain Sustainability 🌳 and Productivity ⌛