The world’s leading publication for data science, AI, and ML professionals.

Automate Graphic Design using Python

Use Python PIL to automate the creation of hundred operational labels for the signage of picking locations in a Warehouse.

(Image by Author)
(Image by Author)

As a data scientist, have you ever wished that graphic design could be as easy as coding a script?

With Python, it can be!

You are a data scientist in the logistics department of an international fashion retailer.

Your colleagues install equipment, train the teams, and design the layouts of storage locations for each new project.

Example of Warehouse Label - (Image by Author)
Example of Warehouse Label – (Image by Author)

Therefore, they spend a tremendous amount of time in graphic design for posters, security signage, and labels.

How can you support them with Python?

This article explores a method to automate the graphic design process using the Python library Pillow.

I. How to do graphic design with Python?
  1. Scenario
  You need to design several hundreds of labels for a warehouse
  2. Objective and Solution
  You want to automate this process using Python Pillow
II. Warehouse Label Design Workflow
  1. Six key parameters
  Each label is defined by components with dedicated spatial locations.
  2. Information sources
  An Excel file store the parameters to generate all your labels
III. Automate the label creation with Python Pillow
  1. Loop Through Your Data Frame using Pandas
  Extract the information of items to include with their spatial locations
  2. Generate a Barcode for the SKU Code with EAN13 library
  Some items need to be generated during the creation of the label.
IV. Conclusion
  1. Animate Python graphs using Pillow
  Another application of Pillow to bring life to your visuals

How to do graphic design with Python?

Scenario

You support the project team for the logistics department of a fashion retailer with warehouses on all continents.

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

Example of a Distribution Center - (Image by Author)
Example of a Distribution Center – (Image by Author)

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

You can have several hundred locations in a warehouse with pallets/shelves for storage and picking.

(Ground Level: Picking Locations, Other Levels: Storage) - (Image by Author)
(Ground Level: Picking Locations, Other Levels: Storage) – (Image by Author)

To help the operators 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)
Example of the label for an elevated storage location – (Image by Author)

What do we want to achieve?

Objective

You want to design customized labels that reduce errors, help operators, and respect your company’s standard operating procedures.

You want to automate this process because you may have several thousand locations per warehouse.

How?

Solution

I will present a solution to automatically create these labels.

Final Results of labels - (Image by Author)
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.

Let’s have a look at it!


Warehouse Label Design

Six key parameters

Three types of operators will read this label:

  • 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

What do we need to include in this label?

Therefore, you must include 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
Label Information - (Image by Author)
Label Information – (Image by Author)

How do we do that?

Let us split the label into single elements.

Spatial Coordinates

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

Key Coordinates - (Image by Author)
Key Coordinates – (Image by Author)

You have five parameters to locate the different items in this straightforward label.

We put the origin in the top-left corner because Python’s Pillow uses the same origin.

From where do we take these elements?

Import PNG icons

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

Icons to add - (Image by Author)
Icons to add – (Image by Author)

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

Great, now how do we know what to put in each label?

Information source

Your master data contains several thousand SKUs with information such as 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, …

Now that you have a clear idea of the workflow let us implement it in a python script.


Automate the label creation with Python Pillow

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 Canvas - (Image by Author)
Blank Canvas – (Image by Author)

Let’s add some illustration in this canva.

Add Icons to the Label using Python’s 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 your background transparent.
  • Icons coordinates are defined using their size on both axes
Label with icons - (Image by Author)
Label with icons – (Image by Author)

This starts to look like a warehouse label.

Let us add the location information.

Generate a Barcode for the SKU Code with EAN13 library

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

P.S:

  • create_ean will generate a PNG file stored locally and used by the script
  • The bar code has been resized to fit in the canvas
Label with bar code - (Image by Author)
Label with bar code – (Image by Author)

This bar code can be scanned by an RF gun.

However, we need to add the location names for the operators.

Add the Location Code to the Label with the Pillow

This last step will be fully performed using Python Pillow.

Final Result - (Image by Author)
Final Result – (Image by Author)

Now our label is complete.

A Python script has entirely generated it.


Conclusion

Your labels are generated and ready to be printed.

Say goodbye to time-consuming Graphic Design tasks and hello to automation with Python Pillow.

1000 labels generated in 30 seconds - (Image by Author)
1000 labels generated in 30 seconds – (Image by Author)

This is not Leonardo Da Vinci’s artwork, but it can be automatically generated for a thousand Labels with just a click.

Do you want other applications of Python Pillow?

Generate Animated Graphs using Pillow

In another series of articles, I focus on implementing an optimization tool to reduce the walking distance of warehouse operators.

Two different pathfinding algorithms - (Image by Author)
Two different pathfinding algorithms – (Image by Author)

The idea is to compare two pathfinding methods for a specific pick mission set.

What’s the problem?

Looking at the final results does not provide enough insights.

I used Python Pillow to generate animated plots with the two pathfinding solutions.

You can now spot when (and where) the two solutions differed.

You can find the detailed solution in this article if you want to replicate this solution.

Animate your Python Graphs with Pillow

Have you heard about Generative AI?

Boost your tool with GPT.

What if users can change the icon type or location using a prompt in plain English?

Large Language Models (LLMs) can be used to improve the user experience for reporting and advanced analytics products.

Supply Chain Control Tower Agent with LangChain SQL Agent [Article Link] - (Image by Author)
Supply Chain Control Tower Agent with LangChain SQL Agent [Article Link] – (Image by Author)

In a previous article, I explored the possibilities of GPT by building a smart agent connected to a TMS database.

This experiment aims to design an intelligent agent equipped with a GPT model and connected to a database.

  1. Users ask operational questions: "Where is my shipment?"
  2. The agent queries the database and extracts the results.
  3. The agent replies with a proper answer.

Can we use this agent to generated custom labels?

Yes!

After OpenAI introduced ChatGPT’s advanced features, we can deploy solutions like this label design tool in a custom GPT.

  • We can include the initial code presented here
  • The agent could change the code based on user requests

Users would upload item master data, and the agent would prepare the labels.

"The Supply Chain Analyst" - (Image by Author)
"The Supply Chain Analyst" – (Image by Author)

You can get inspiration from the "Supply Chain Analyst", a custom GPT agent I’ve designed to automate supply chain analytics tasks and interact with users using natural language.

For more details, have a look at these articles,

Create GPTs to Automate Supply Chain Analytics

Leveraging LLMs with LangChain for Supply Chain Analytics – A Control Tower Powered by GPT


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

About Me

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

For consulting or advice on analytics and sustainable supply chain transformation, feel free to contact me via Logigreen Consulting.

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

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

Samir Saci | Data Science & Productivity


Related Articles