Imagemagick, Docker, DevOps – Bulk processing images with Imagemagick and Docker, DevOps solution. A quick comparison with Photoshop scripts, Craft solution.

Using a Docker & Imagemagick bundle to replace Photoshop for resizing and optimizing bunch of images is not totally irrelevant. Why that? Besides the fact that It gave you the insurance to execute properly a repetitive task, it has several benefits that I listed. I am not talking about an advanced usage made, for instance, by a web designer. The subject of this post is managing thousand of images, that is key in a digital workflow. This is one of the most time-consuming charges in the content creation workload. On my own, I made a real Spike on that subject!

All the files are on githubin images_treatment_photoshop_imagemagick_docker on Github

For those who ignore what a Spike in Scrum? Here is a quick definition:
“Spikes are an invention of Extreme Programming (XP), are a special type of user story that is used to gain the knowledge necessary to reduce the risk of a technical approach, better understand a requirement, or increase the reliability of a story estimate. A spike has a maximum time-box size as the sprint it is contained in it. At the end of a sprint, the spike will be determined that is done or not-done just like any other ordinary user story. A Spike is a great way to mitigate risks early and allows the team ascertain feedback and develop an understanding on an upcoming PBI’s complexity.”


Some benefits to move from Photoshop to Docker/Imagemagick.

  • Image quality: no trade-off with image quality and reducing time-consuming task to work on image.
  • Docker: good empiric introduction to automation, industrialization, CI, with a sharable and maintainable environment.
  • Open Source: imagemagick, Docker are free. It is saving money and time, less training, no licensing. There is only the learning curb that may cost you time. No Pain No Gain!
  • User-Experience: above all saving time to work for the editorial team, time to write and think. Same usages allow better support.
  • Textbook case It is a pragmatic textbook case to show progress from craft usage to industrial usage and how Docker can help you in that?

So, how can batch image processing can reduce this creation process from hours to just a few simple clicks? For this tedious task, why don’t we try to replace Photoshop by a bundle with Imagemagick & Docker? This is the subject of this post.

The user story will be: As an editor, journalist, contributor, I focus only on the image editorial choice and with the help of a bulk processing, a script runs to convert the images into the right format for publishing.I had always this idea somewhere in my mind to leverage on Imagemagick and Docker to batch this image treatment an give a workable alternative to Photoshop.

In my github, you will find even more, a tiny manual written when I was in Zambia, 3 additional use cases and a bunch of Youtube video. I am not cheating you!

  1. USECASE_1 Scripting resize with Photoshop, Scripting with Applescript and Photoshop
  2. USECASE_2 Scripting resize with Imagemagick install on your computer
  3. USECASE_3 Scripting resize with Imagemagick and Docker

Looking for the perfect Docker image with Imagemagick

Inevitably other people, more experienced in development than I am, thought about this topic. So, my sole quest was to pull a docker image that already exist containing Imagemagick.

This docker image will be the “base” for industrialization work for resizing and optimization images. This is also a “killing two birds with one stone” operation as it will de facto standardize usages and practices for any member of the editorial team and ease the support pain.

This is a very simple decision criterion which militates for the choice of the Docker and Imagemagick tandem. This criterion is very simple, imagine that you must equip each computer with a Photoshop license or any software and possibly provide training, in short, this is inflation guaranteed.

Another advantage, using the Docker and Imagemagick tandem will prevent you from buying, installing, training and support each user with a specific software like Photoshop or Gimp even though Gimp is free. A true nightmare.

However, let’s go back to the original need: preparing images for a web or mobile publication, it is mainly to select and then resize the image that match editorially with your content and fit you applications (website, mobile application…).

In a practical way, working images is essentially to export images at the right settings (72 dpi, format 16/9 or 4/3, correct filename…) and the rest we do not give a f…

Implementing D&I (Docker & Imagemagick) will accidentally also cut down the whining refrains from anyone such as “My computer is too slow”, “I am not trained”, “I do not have the license”, “Selecting image is part of my job but not the resizing and the optimizing”… so many popular refrains whose intensity is multiplied by ten due to lockdown.

Listing the benefits can only motivate you to adopt this solution. By the way, you can pretend it is DevOps but at the very first place, it is common sense.

Frankly, I do not understand why on both side there is so much misunderstanding. I am about to believe that people are “stupid” when they reach their point incompetence?

On one side, DevOps do not think about such evolution. Maybe because they ignore everything on content creation workflow. On the other side, Editorial team do not dare to ask for such tool because they basically ignore that there is a possible alternative to Photoshop for instance. Anyway, no collaboration, no smart evolution, just an incredible mess that generate endless errors and support tickets! What a waste of time!

Lockdown spotlight with cruelty the lack of common understanding. You may find this conclusion bitter but unfortunately it seems to be true.

I quote this post in my sister’s blog that summarize this impression during the lockdown.

“Another thing also jumps out at us: the amazing social uselessness of certain professions. Marketer, advisor, financier, manager, and so on. When I think that we have not even realized that these auxiliary services of our sophisticated economy were at a standstill. Neoliberalism will therefore have succeeded where communism had failed: employing lots of people to do unnecessary things!”


Like said Peter Drucker: “There is surely nothing quite so useless as doing with great efficiency what should not be done at all.”

Time to think is over, no kidding!

Using the Docker image with Imagemagick

These are the main commands for exploring Imagemagick and Docker. Don’t forget to start Docker before.

1. Install Imagemagick and Docker

# launch the console
cd /Volumes/mi_disco/imagemagick_docker_1
# make a docker pull from this distribution
docker pull dpokidov/imagemagick
# create the environment
cd /Volumes/mi_disco/imagemagick_docker_1/
# create the source and destination folders for your batch image processing
make 01_source_images
make 02_destination_images
# I have these 2 directories on a remote disk
# /Volumes/mi_disco/imagemagick_docker_1/01_source_images
# /Volumes/mi_disco/imagemagick_docker_1/02_destination_images

Playing with Imagemagick and Docker

1. resize with -resize 100×100 that force to resize

docker run -v /Volumes/mi_disco/imagemagick_docker_1/01_source_images:/imgs dpokidov/imagemagick /imgs/big_nature_1_1920x1080_257525.jpg -resize 100x100 /imgs/resized_big_nature_1_1920x1080_257525.jpg

2. resize with 400x on with and the height is proportional

docker run -v /Volumes/mi_disco/imagemagick_docker_1/01_source_images:/tata dpokidov/imagemagick /tata/big_nature_2_1920x1080_257635.jpg -resize 400x /tata/resized_big_nature_2_1920x1080_257635.jpg

3. resize with 600x on with and the height is proportional

docker run -v /Volumes/mi_disco/imagemagick_docker_1/01_source_images:/source -v /Volumes/mi_disco/imagemagick_docker_1/02_destination_images:/destination dpokidov/imagemagick /source/big_nature_3_1920x1080_257528.jpg -resize 600x /destination/fuck_big_nature_3_1920x1080_257528.jpg

4. resize to 50%

docker run -v /Volumes/mi_disco/imagemagick_docker_1/01_source_images:/source -v /Volumes/mi_disco/imagemagick_docker_1/02_destination_images:/destination dpokidov/imagemagick /source/big_nature_2_1920x1080_257635.jpg -quality 100 -resize 50% -interlace plane /destination/resize_50_big_nature_2_1920x1080_257635.jpg

Conclusion: Indeed, it is a strong move and a bold decision to go for Imagemagick & Docker (I & D). First, it does NOT mean that you have to renounce to Photoshop. Just focus on cracking down in micro tasks your conditioning images working workflow and expel most boring, tedious and repetitive actions to this I & D environment using programming to perform its.
Last but not least, it supposes also that the DevOps you are working with have understood your automation needs that is may be the most difficult part of the program!

Videos for this post

All the videos are available on YouTube in this playlist:

  • Video #1 Quick intro on Bulk processing images, DevOps solution (Imagemagick, Docker) vs Craft solution (Photoshop)
  • Video #2 Bulk processing images using a Craft solution with Photoshop & AppleScript
  • Video #3 Bulk processing images using a semi-automated solution with Imagemagick & Homebrew
  • Video #4 Bulk processing images using a DevOps solution Imagemagick & Docker
  • Video #5 Bulk processing images advanced practices for a DevOps solution, using Imagemagick & Docker, insights on Makefile, Dockerfile

Read more