Git Product home page Git Product logo

brickify-old's Introduction

THIS IS AN OLD VERSION. SEE VERSION 2 FOR A BIG UPDATE.

Brickify

Turn images into lego mosaics.

Example

Code Sample

from PIL import Image
from brickify import EditedImage, PieceList, RenderedImage
from defaults.palettes import all   #use the default lego color palette 
from defaults.pieces import medium #use medium piece sizes 


IMAGE = 'barack.jpg'
INPUT_PATH = 'input/'
OUTPUT_PATH = 'output/'

SIZE = (96, 96)   # each pixel will be treated as a (1x1) lego brick

im = Image.open(INPUT_PATH + IMAGE)   # open the image

edited = EditedImage(image = im).edit_image(size = SIZE, palette = all) #resize the image and recolor it to the lego colors
pieces = PieceList(image = edited).generate_medium(pieces = medium)  #use medium sized pieces and generate with medium speed. 
#Medium speed is not optimized to fit the biggest piece when possible. 
#use the generate_slow method if you're looking for optimization.
#use the generate_fast method if you're looking for speed.  

render = RenderedImage(piece_list = pieces, size = SIZE).render_image() #render the piecelist into a visual form. 

render.save(OUTPUT_PATH + IMAGE) #save the render you created. 

Image Output

Image

Other Examples

Image Image

Image Image

Image Image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.