The author writes with you a small project, which draws images from other images, creating a mosaic. Of course, we will implement this using Golang (because it is stylish, trendy, and fast, of course).
Our task sounds like this:
You need to get one image and draw each pixel from that image using a small image, so to get a “mosaic” an image of hundreds of little ones.
I will use my avatar as the source image (more than me, lol). And as parts of the mosaic, icons from WoW (since there are many of them to complete the palette). As a result, we should get something like this:
So, let’s go!
As usual, first, we create
main.go with a template for our builder.
Let’s start with Image Processing with Go
Next, we need our icons, with which we will lay out the mosaic. As I said above, here we will focus on the icons from the World of Warcraft game. You can use absolutely any images, as long as they are square and there are many.
Okay, we have downloaded our icons, and put them somewhere, but we need to know all the pictures we will use to build our image. To do this, we will write a function that will traverse the directory tree with pictures and return a flat list of paths.
Let’s add the
getPartsPaths function and fix the path to the icons and their size in our collector.