Generate Awesome Photomosaics On Linux With Metapixel

Ok, I admit. I thrashed the servers for a little while using an open source website mirroring tool, which I wont mention, but it’s easy to find. 🙂

About 30,000 user icons later, I present to you a product created by a couple very short and sweet command line tools.



On an unrelated note, I’ll be disabling hotlinking of images shortly, so if you’re going to steal my content, please rehost these images yourself.

So how can you make your own mosaic? Simple! Download and install metapixel, if you’re running Ubuntu, it’s located in the universe repository.

Then we are just a few commands away from generating sweet photomosaics. First, we prepare the images.

metapixel-prepare -r source destination --width=48 --height=48

This copies all images from the “source” folder, (recursively) searching into every folder within, and dumps every image it finds into the “destination” folder after resizing them into 48×48 pixel images. You’ll want to modify the width and height to fit the source images. This took a LONG time for me, since my library of images was so gigantic – but once we’re done preparing the images, you don’t have to do it again. Woohoo!

Next, we actually generate the output file(s) with this one liner:

metapixel --metapixel input.jpg output.png --library destination --scale=35 --distance=500

This takes input.jpg and increases the output size by 35 times (i.e. REALLY BIG IMAGE), uses the library destination and does not repeat any images found in the library closer than 500. It’ll spit output.png after a little while. If you don’t care about repeating images, removing the distance flag will result in MUCH, MUCH faster generation times.

Here’s a another I generated, this HUGE image was scaled down from about 228 megapixels.


In related news, here’s a groovy post over at Kristen Symonds’s blog with a ton of GIMP/Photoshop brushes, check it out, good stuff. 🙂

Which images would you like to see rendered in Digg user icons? I’ve got lots more ideas but not much time to use them, since I’ve got some holiday shopping to do. 🙂

I’m back, here are some more…





Ok last update, promise… this is actually pretty darn fun.

Last Jedi Supper:
The original was a 460 megapixels PNG file (30720×15040 – 370MB) scaled down to 7680×3760 – only 28MP, saved as 70% quality JPEG ended up as about a 7MB file… still HUGE! The GIMP was using about 1.2GB of RAM (Thank god I upgraded last week to 4GB!) while scaling the image.


63 replies on “Generate Awesome Photomosaics On Linux With Metapixel”

Very cool rendition of starry night. What were the source images? Kind of look like avatars.

Thanks for the link. Just curious – how did you find my full name? I know it’s possible, just didn’t know it was easy 🙂

True enough! Don’t use HTTrack for evil…

I can remember a few incidents where I left it running and came back to see that I had downloaded dozens of GB worth of data from an extremely unhappy web server.

I’ve learned to set limitations where it wont download more than say, 500MB at most in a session.

Ahhh… hotlinking is now disabled… and I COULD have been evil about it, but nah. 🙂

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^*$ [NC]
RewriteCond %{HTTP_REFERER} !^*$ [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ [R,NC]

What a superb bit of code! Sorry Roy 😉

Snap! Hotlinking is a little bit more involved than I thought… I think I’m going to need to use a blacklist instead of a whitelist… time to setup a cronjob and email myself the worst offenders on a daily basis. 🙂 To the person that I broke Google Reader on – whoops!

Is there any chance you could give an example for the code to be put into the terminal?

Say for example I have all the pics I want to use in a folder in my home directory called pics

I then have the input image in a folder in my home directory called source pic (the actual photo is called pic1.png)

What would I need to type into terminal, sorry for being so noob

Great! Is there a list of user-names of the avatars you used for this project?

I’d love to check for mine! (Without hours of finding waldo…)

The instructions given earlier suggest using in input image of type jpg, but png should work, as gif does.

Step 1, create a library folder to toss the icons into:
mkdir ~/metapixel

Step 2, convert that library of images you have already, into icons of 48×48 size:
metapixel-prepare -r ~/pics ~/metapixel –width=48 –height=48

Step 3, we actually generate the output file:

metapixel –metapixel ~/source/pic1.png output.png –library ~/metapixel –scale=35 –distance=500

You did not specify the destination directory for output.png, so it will put it into whatever folder you are in when you enter the commands.

If the collection of photos you start out with is not large enough, you may need to change the distance value to a smaller number.

I am very curious about the collection side of this. Where you able to collect only the images or did you have to some how filter them out after the fact. Perhaps another tutorial about running webHTTrack. I am also curious about what hardware you are using and the time to complete this task on said hardware.

Another great article, keep up the good work.

I forgot to mention that you should submit your picture of Imogen to… I didn’t know who she was so I went and checked out her site. It looks like they accept user submissions of pictures.

Do you know the idea of 6-degrees of separation?

I spider’d 2 degrees of 1 user with HTTrack, which generated over 30,000 user icons, I can only imagine how many 6 degrees would have given me… probably 500,000 or so.

I only downloaded the low quality version of the user avatar to save their bandwidth – it has the same filename for each user, so it was easy to filter out everything but png files with a specific name.

There was very, very little after the fact filtering, since I used appropriate rules to limit the download to ONLY what I wanted to get.

I did NOT want to really abuse and hammer the crap out of someone else’s servers (that’s just rude), and when I was done I clicked on a bunch of their silly ads to restore my karma.

I used an open source tool FSLint to remove exact binary duplicates, and right there a TON of people who still use the default avatar are culled, along with people who uploaded the same original file as an avatar.

In some of these renderings, I changed how often the images could repeat, so for example in the Jedi Last Supper you can see images repeating fairly often when you zoom all the way in.

Truly awesome. Just one question: Where can I get a collection of images to thumbnail for the mosaic? Currently, I have a collection of around 1500 personal images but the generated mosaic is still non-descript. I cannot specify a distance of more than 25.

Is your image collection somewhere on the web — i.e. freely downloadable?


Thanks for putting this how-to together, Wayne. I learned a few extra commands from it that I didn’t know of before.

If any of your readers are interested, I’ve had a tutorial made for a while now that outlines this same process. The only difference is that I’ve used a few other tricks and commands to get the results that I was personally after. It may help your readers too.

Here’s the link:
Great Photo Mosaics with Metapixel

Hey can some one help a total noob with this? `When i type the command to prepare the pics i get this:

Usage: /usr/bin/metapixel-prepare [OPTION]…

Prepares all images in for use as small images in
photomosaics. The scaled versions and the table file are
stored in .

–help display this help and exit
–width=WIDTH specify width of small images
–height=HEIGHT specify height of small images
-r, –recurse recurse through directories
–debug print out debugging info
As i’m new to linux i don’t know what i’m doing wrong. I’ve copied the source folder to my home folder and created the destination folder there and followed the instructions posted by rusty but i still get that same output. I know i must be doing something dumb, can anyone help please?

[…] Generate Awesome Photomosaics On Linux With Metapixel | fsckin w/ linux So how can you make your own mosaic? Simple! Download and install metapixel, if you’re running Ubuntu, it’s located in the universe repository. Then we are just a few commands away from generating sweet photomosaics. First, we prepare the images. (tags: art design visualization graphics tools photography linux) […]

Uhh..Wow. I need some help with my mosaic. I think I may have done something wrong:

Image Type: png (The PNG image format)
Width: 58816 pixels
Height: 36800 pixels
Size: 1.5 GB (1557661764 bytes)

When I try to open it:
“Insufficient memory to store a 58816 by 36800 image; try exiting some applications to reduce memory usage”

When I try to open it in firefox – firefox complains it contains errors.

Now, should I make a smaller one or is there some how I can view this and then print it to make one helluva poster?

Heh..triple posting for the win.

Anyway. Opening it with gimp – taking a while but it may work.

Nope – gimp froze.

Halp, it’s a damn big image and some programs will have a heart attack.
GIMP should be able to open it – eventually. You’ll need a lot of patience… put a movie on or something!

Sorry, no idea.

Are you really trying to make a poster 16 feet long? Because that’s what you’re file will produce printed at 300dpi. I don’t think large posters are usually printed at high resolution because they’re designed to be viewed far away, they don’t need to be high res.

I think you might just need a smaller file to open it with a regular computer.

Abandoning this now is madness! I must follow through! Wayne – I am calling upon you for you guidance! NOW ANSWER ME!


We are a bunch of volunteers and opening a brand new scheme in
our community. Your web site offered us with valuable info
to work on. You have done an impressive process and our whole
community might be grateful to you.


Leave a Reply

Your email address will not be published. Required fields are marked *