C# Image Resizer Using ZeroMQ

Introduction I previously served as the General Secretary of an association based in Brisbane. Throughout the year, we host around three events where professional photographers capture numerous high-quality images. Some of these photos can be as large as 18MB. Once the events conclude, the pictures need to be uploaded to Google Albums and shared with our community. At our most recent event, the total upload size reached 5GB. I had previously implemented an image resizer in php which I executed by running php process.php imageprocessing [ []] The files in the input folder were processed sequentially, which worked well for a small number of images and for smaller file sizes—around 5MB. However, when handling a large volume of files, the process became slow and occasionally crashed due to PHP running out of memory. A more efficient approach would be to distribute the resizing task across multiple workers. This can be achieved using a simple pub/sub messaging pattern, where the publisher gathers a list of all images to be processed and then sends messages containing the necessary details for resizing. The workers retrieve messages from the queue and handle their processing. A message can be defined as { "Id": "1", "Filename": "2025\\MENS EVENT_2025\\1D2A7537.JPG", "InputFolder": "2025\\MENS EVENT_2025", "OutputFolder": "2025\\MENS EVENT_2025_CSharp", "Resize": 20 } Solution The ImageProcessor in the repository has been implemented in C# using ZeroMQ and the NetMq nuget package. It also uses SixLabors.ImageSharp to resize the image. It consists of Publisher project - ImageListing Worker project - ImageProcessor The publisher The worker Both projects can be used as follows: .\ImageListing.exe "\2025\MENS EVENT_2025" "2025\MENS EVENT_2025_CSharp" 20 .\ImageProcessor.exe 1 .\ImageProcessor.exe 2 .\ImageProcessor.exe 3 .\ImageProcessor.exe 4 Finally I began experimenting with ZeroMQ in October 2024 while searching for an embedded library—similar to SQLite—that wouldn't require installing additional software. There are other message brokers such as Rabbitmq, ActiveMQ, Azure Service Bus and Aws SNS/SQS. I worked on Java-HowTo-SNS utilizing AWS SNS for a similar task in Java. Using ZeroMQ offered a more complete and contained solution. Additionally, by integrating ImageSharp, watermarks can be seamlessly added to images during resizing.

May 1, 2025 - 01:26
 0
C# Image Resizer Using ZeroMQ

Introduction

I previously served as the General Secretary of an association based in Brisbane. Throughout the year, we host around three events where professional photographers capture numerous high-quality images. Some of these photos can be as large as 18MB.

Once the events conclude, the pictures need to be uploaded to Google Albums and shared with our community. At our most recent event, the total upload size reached 5GB.

I had previously implemented an image resizer in php which I executed by running

php process.php imageprocessing  [ []]

The files in the input folder were processed sequentially, which worked well for a small number of images and for smaller file sizes—around 5MB.

However, when handling a large volume of files, the process became slow and occasionally crashed due to PHP running out of memory.

A more efficient approach would be to distribute the resizing task across multiple workers. This can be achieved using a simple pub/sub messaging pattern, where the publisher gathers a list of all images to be processed and then sends messages containing the necessary details for resizing.

The workers retrieve messages from the queue and handle their processing.

A message can be defined as

{
  "Id": "1",
  "Filename": "2025\\MENS EVENT_2025\\1D2A7537.JPG",
  "InputFolder": "2025\\MENS EVENT_2025",
  "OutputFolder": "2025\\MENS EVENT_2025_CSharp",
  "Resize": 20
}

Solution

The ImageProcessor in the repository has been implemented in C# using ZeroMQ and the NetMq nuget package. It also uses SixLabors.ImageSharp to resize the image.
It consists of

  1. Publisher project - ImageListing
  2. Worker project - ImageProcessor

The publisher
Image description

The worker
Image description

Both projects can be used as follows:

.\ImageListing.exe "\2025\MENS EVENT_2025" "2025\MENS EVENT_2025_CSharp" 20

.\ImageProcessor.exe 1
.\ImageProcessor.exe 2
.\ImageProcessor.exe 3
.\ImageProcessor.exe 4

Finally

I began experimenting with ZeroMQ in October 2024 while searching for an embedded library—similar to SQLite—that wouldn't require installing additional software.

There are other message brokers such as Rabbitmq, ActiveMQ, Azure Service Bus and Aws SNS/SQS. I worked on Java-HowTo-SNS utilizing AWS SNS for a similar task in Java.

Using ZeroMQ offered a more complete and contained solution. Additionally, by integrating ImageSharp, watermarks can be seamlessly added to images during resizing.