Mozaic is a jQuery based JavaScript library for transforming a picture into a photomosaic of small thumbnail images.
The underlying data structure used to find the closest tile image is a kd-tree with k=3. This library is adapted from the Data Structures and Algorithms class at the University of Illinois at Urbana-Champaign. Mozaic is available under the MIT License.
Want to learn more? See the wiki.