Low Poly Image Transformation

Origin Story

After having the same profile picture on Facebook for some years, I wanted to get a new one. I'd seen a sort of artwork where a person's face was broken into a bunch of triangles. Some quick searching learned me that this style was called low poly. After searching some more, I unfortunatly only found one guide on how to recreate this style. In summary: buy Adobe Photoshop and painstakingly select each triangle manually. Adjust the triangles until it looks the way you want.

Wow. There's no way to do this automatically? Let's change that.

What it does

When you select a picture, the script will try it's very best to create a nice low poly version of it. To give you some control over the result, there are two sliders: treshold and triangles.
The treshold slider determines how agressively the script creates triangles. If you set the slider very high, some parts of the image won't be transformed and you'll get mostly large triangles. If you set the slider very low, you'll get triangles for the smalles change of shade, resulting in smaller triangles.
The triangles slider simply determines how many triangles are created. More triangles doesn't always mean a nicer result and more triangles also means more processing time.

How it does it

When you upload a picture, the script does a bunch of calculations to find candidate triangles. The points of the triangles are selected based on the difference in color with surrounding pixels. For example, the color of the pixels on the edge of your face will probably be very different from the neighbouring pixels that are part of the background, so we may want to have an edge of a triangle there.