Giter Club home page Giter Club logo

legofy's Introduction

Legofy Build Status PyPI Downloads PyPI version License Coverage Status Code Health Join the chat at https://gitter.im/JuanPotato/Legofy

What is it?

Legofy is a python program that takes a static image or gif and makes it so that it looks as if it was built out of LEGO.

Before

After

Requirements

  • Python
  • Python modules: Pillow, click # pip will install these automatically if using pip install legofy
  • imagemagick # not needed but recommended

Bugs

If you find a bug:

  1. Check in the open issues if the bug already exists.
  2. If the bug is not there, create a new issue with clear steps on how to reproduce it.

Quickstart

$ pip install legofy

or install from source

$ git clone https://github.com/JuanPotato/Legofy.git
$ cd Legofy
$ python setup.py install

Wait! I don't know what any of this means? Use pip then, or if you really want to install from source have some help.

Usage

Usage: legofy [OPTIONS] IMAGE [OUTPUT]

  Legofy an image!

Options:
  --size INTEGER                  Number of bricks the longest side of the legofied image should have.
  --dither / --no-dither          Use dither algorithm to spread the color approximation error.
  --palette [all|effects|mono|solid|transparent]
                                  Palette to use based on real Lego colors.
  --help                          Show this message and exit.

Palette

There are 3 palettes: solid (33 colors), transparent (14 colors) and effects (4 colors). You can use one of them or all the 3.

$ legofy --palette solid image.jpg
$ legofy --palette transparent image.jpg
$ legofy --palette effects image.jpg
$ legofy --palette all image.jpg

There is another one palette, mono, with only 2 colors (black and white...). It's just for test and fun...

Troubleshooting

Installation

  1. Download and install all requirements
  1. Download this project by using the download zip button on this page, or running git clone https://github.com/JuanPotato/Legofy
  • If you downloaded a zip file, please unzip it
  1. Open a command line and navigate to the project folder
  2. Run python setup.py install while in the project folder
  3. You can now use Legofy anywhere, see usage for more help

Forks

legofy's People

Contributors

armel avatar christoga avatar cyberriman avatar gitter-badger avatar itcave avatar jightuse avatar juanpotato avatar jungx098 avatar lamby avatar levikanwischer avatar livibetter avatar marcoceppi avatar nabijaczleweli avatar nils-werner avatar niroyb avatar romanpitak avatar taranjeet avatar wildhoney avatar xbluedogx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

legofy's Issues

Need a better 1x1 Lego Piece and 1x2 2x1

BETTER ones... If anyone with photoshop knowledge could recreate a 1x1 lego piece and/or create the 2x1 and 1x2 pieces? I was hoping to have a brand new piece so that I can make sure the base color of the lego is 128,128,128

ValueError:

I ran the following: sudo python setup.py install and at the end of the program I got this ValueError: --enable-jpeg requested but jpeg not found, aborting.

Is there a jpeg missing?

Tries to write new image to / (Permission denied)

Hi,

legofy tries to write the new image to /. Results in a permission denied error.

$ python legofy/cli.py 2014-08-08.jpg
Static image detected, will now legofy and save as /lego_2014-08-08.png
Traceback (most recent call last):
  File "legofy/cli.py", line 17, in <module>
    main()
  File "/home/dan/workspace/playground/legofy/lib/python3.5/site-packages/click/core.py", line 700, in __call__
    return self.main(*args, **kwargs)
  File "/home/dan/workspace/playground/legofy/lib/python3.5/site-packages/click/core.py", line 680, in main
    rv = self.invoke(ctx)
  File "/home/dan/workspace/playground/legofy/lib/python3.5/site-packages/click/core.py", line 873, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/dan/workspace/playground/legofy/lib/python3.5/site-packages/click/core.py", line 508, in invoke
    return callback(*args, **kwargs)
  File "legofy/cli.py", line 14, in main
    legofy.main(image, brick=brick)
  File "/home/dan/workspace/playground/legofy/lib/python3.5/site-packages/legofy-0.0.1-py3.5.egg/legofy/__init__.py", line 131, in main
    makeLegoImage(baseImage, brick).save(newFilename)
  File "/home/dan/workspace/playground/legofy/lib/python3.5/site-packages/PIL/Image.py", line 1659, in save
    fp = builtins.open(filename, "wb")
PermissionError: [Errno 13] Permission denied: '/lego_2014-08-08.png'

Remove cli.py from coverage

Coverage should be better.
Remove cli.py from coverage or add a test to add coverage to it.
I tried to add a test but failed to get it working with click.

Legofy wont work

I try to run setup.py but the system is ignoring me,
Please fix

Here is my terminal :

$ python setup.py install
running install
Checking .pth file support in /Library/Python/2.7/site-packages/
error: can't create or remove files in install directory

The following error occurred while trying to add or remove files in the
installation directory:

    [Errno 13] Permission denied: '/Library/Python/2.7/site-packages/test-easy-install-31852.pth'

The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:

    /Library/Python/2.7/site-packages/

Perhaps your account does not have write access to this directory?  If the
installation directory is a system-owned directory, you may need to sign in
as the administrator or "root" account.  If you do not have administrative
access to this machine, you may wish to choose a different installation
directory, preferably one that is listed in your PYTHONPATH environment
variable.

For information on other options, you may wish to consult the
documentation at:

  https://pythonhosted.org/setuptools/easy_install.html

Please make the appropriate changes for your system and try again.

$ legofy
Traceback (most recent call last):
  File "/usr/local/bin/legofy", line 5, in <module>
    from pkg_resources import load_entry_point
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 2793, in <module>
    working_set.require(__requires__)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 673, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 576, in resolve
    raise DistributionNotFound(req)
pkg_resources.DistributionNotFound: pillow

UnicodeEncodeError on file param

Run:

$ legofy /home/xxx/Imágenes/4.jpg

Get Error:

Traceback (most recent call last):
  File "/usr/local/bin/legofy", line 9, in <module>
    load_entry_point('legofy==0.0.1', 'console_scripts', 'legofy')()
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 700, in __call__
    return self.main(*args, **kwargs)
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 680, in main
    rv = self.invoke(ctx)
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 873, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/lib/python2.7/dist-packages/click/core.py", line 508, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/legofy-0.0.1-py2.7.egg/legofy/cli.py", line 16, in main
    legofy.main(image, brick=brick)
  File "/usr/local/lib/python2.7/dist-packages/legofy-0.0.1-py2.7.egg/legofy/__init__.py", line 84, in main
    newFilename = '{0}/lego_{1}'.format(*os.path.split(filename))
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1' in position 13: ordinal not in range(128)

Brick count stats - feature request

Maybe, it would be really nice to save (with param --statistics or whatever) counts of brick with colors. Something like

red: 5; blue: 50

I really love this project and I would like to create real Lego picture from my photo, but counting brick.. hmmm.. :)

Thanks!
Ajaxovic

How to run Legofy?

Normally, when I try a new project, I don't install it, but Legofy don't seem to let me to run it directly, using 616af86.

Run without installation

I have tried:

python legofy/__init__.py
python legofy/cli.py
python -m legofy.__init__

Which is expected, nothing happens as the code doesn't do anything in running this way. Do I have to install for entry point script in order to try it out?

Run after installation

I installed with

pip install --user .

But, the asset bricks/brick.png isn't installed:

% legofy spinner.gif
Animated gif detected, will now legofy each frame and recreate the gif and save as lego_spinner.gif
Working on frame_0003.png
Traceback (most recent call last):
  File "/home/livibetter/.local/bin/legofy", line 9, in <module>
    load_entry_point('legofy==0.0.1', 'console_scripts', 'legofy')()
[snip]
  File "/home/livibetter/.local/lib64/python2.7/site-packages/legofy/__init__.py", line 54, in makeLegoBrick
    return applyEffect(Image.open(brick), colorize)
  File "/usr/lib64/python2.7/site-packages/PIL/Image.py", line 2248, in open
    fp = builtins.open(fp, "rb")
IOError: [Errno 2] No such file or directory: '/home/livibetter/.local/lib64/python2.7/site-packages/legofy/bricks/brick.png'

So, I tried with --brick, but here isn't defined when run with the option, hence:

% legofy --brick /tmp/Legofy/legofy/bricks/brick.png spinner.gif
Traceback (most recent call last):
  File "/home/livibetter/.local/bin/legofy", line 9, in <module>
    load_entry_point('legofy==0.0.1', 'console_scripts', 'legofy')()
[snip]
  File "/home/livibetter/.local/lib64/python2.7/site-packages/legofy/cli.py", line 13, in main
    legofy.main(image, brick=os.path.join(here, 'bricks', 'brick.png'))
UnboundLocalError: local variable 'here' referenced before assignment

Unable to convert - NotADirectoryError

I am trying to convert an image and getting this error

$ legofy wait-what.jpg 
Static image detected, will now legofy and save as /lego_wait-what.png
Traceback (most recent call last):
  File "/home/anand/.virtualenvs/3/bin/legofy", line 9, in <module>
    load_entry_point('legofy==0.0.1', 'console_scripts', 'legofy')()
  File "/home/anand/.virtualenvs/3/lib/python3.4/site-packages/click-5.1-py3.4.egg/click/core.py", line 700, in __call__
  File "/home/anand/.virtualenvs/3/lib/python3.4/site-packages/click-5.1-py3.4.egg/click/core.py", line 680, in main
  File "/home/anand/.virtualenvs/3/lib/python3.4/site-packages/click-5.1-py3.4.egg/click/core.py", line 873, in invoke
  File "/home/anand/.virtualenvs/3/lib/python3.4/site-packages/click-5.1-py3.4.egg/click/core.py", line 508, in invoke
  File "/home/anand/.virtualenvs/3/lib/python3.4/site-packages/legofy-0.0.1-py3.4.egg/legofy/cli.py", line 14, in main
  File "/home/anand/.virtualenvs/3/lib/python3.4/site-packages/legofy-0.0.1-py3.4.egg/legofy/__init__.py", line 131, in main
  File "/home/anand/.virtualenvs/3/lib/python3.4/site-packages/legofy-0.0.1-py3.4.egg/legofy/__init__.py", line 67, in makeLegoImage
  File "/home/anand/.virtualenvs/3/lib/python3.4/site-packages/legofy-0.0.1-py3.4.egg/legofy/__init__.py", line 54, in makeLegoBrick
  File "/home/anand/.virtualenvs/3/lib/python3.4/site-packages/PIL/Image.py", line 2249, in open
    fp = builtins.open(filename, "rb")
NotADirectoryError: [Errno 20] Not a directory: '/home/anand/.virtualenvs/3/lib/python3.4/site-packages/legofy-0.0.1-py3.4.egg/legofy/bricks/brick.png'

Legofy animated gif results in OSError: [Errno 2] No such file or directory

15.0.0 Darwin Kernel Version 15.0.0: Sat Sep 19 15:53:46 PDT 2015; root:xnu-3247.10.11~1/RELEASE_X86_64 x86_64

Animated gif detected, will now legofy each frame and recreate the gif and save as lego_pixel_waterfall_bg__by_isohei-d4xntof.gif
Working on frame_0000.png
Working on frame_0001.png
Working on frame_0002.png
Working on frame_0003.png
Working on frame_0004.png
Working on frame_0005.png
Working on frame_0006.png
Working on frame_0007.png
convert -delay 10 -loop 0 ./tmp_frames/*.png /lego_pixel_waterfall_bg__by_isohei-d4xntof.gif
Traceback (most recent call last):
  File "/usr/local/bin/legofy", line 9, in <module>
    load_entry_point('legofy==0.0.1', 'console_scripts', 'legofy')()
  File "/Library/Python/2.7/site-packages/click/core.py", line 700, in __call__
    return self.main(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/click/core.py", line 680, in main
    rv = self.invoke(ctx)
  File "/Library/Python/2.7/site-packages/click/core.py", line 873, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Library/Python/2.7/site-packages/click/core.py", line 508, in invoke
    return callback(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/legofy-0.0.1-py2.7.egg/legofy/cli.py", line 14, in main
    legofy.main(image, brick=brick)
  File "/Library/Python/2.7/site-packages/legofy-0.0.1-py2.7.egg/legofy/__init__.py", line 119, in main
    call(command.split(" "))
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 522, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__
    errread, errwrite)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

Add ability to adjust resolution

Please add ability to adjust "resolution" of the output image. I don't necessary mean the output size of the brick, more that the image size of the output changes to include less or more detail of the original.

Add ability to change scale of lego peices

For example, each lego block in the output image is essentially a pixel. The user should be able to specify the new "resolution" for their image as a command line option.

ValueError: --enable-zlib requested but zlib not found, aborting.

/sysinfo

• System Information: Model: Mac Mini (Late 2014) 
• CPU: Intel Core i5-4278U (4 Threads, 2 Cores) @ 2.60 GHz 
• Memory: 8.00 GB • Uptime: 5 hours • Disk Space: 998.98 GB 
• Graphics: Intel Iris 
• Screen Resolution: 1920 x 1080 
• OS: OS X El Capitan (Version 10.11.1, Build 15B42)

info

Full log

Optimized gifs come out broken

Any gifs that are optimized and have pieces of frames deleted will form broken gifs once legofied. By broken I mean that the frames will look glitchy. I found this and will implement it tomorrow, if anyone finds anything better, please tell me.

Don't bake shading on output

Two ideas:

  • output two images instead of the baked one: difusse and normal-map. This way people can add lighting on post-production and better fake a lego-video.
  • related to the earlier. add an option to specify a virtual light and output the rendered image.

Add description to repo

The repo is missing a description.
image
It would look nicer with one. Since it's not something we can do a pull request on, I'm marking it as an issue.

Could be as simple as : "Legofy images!"

TypeError: 'int' object has no attribute '__getitem__'

Cannot get it to run, because of
TypeError

$ python legofy/cli.py nexmo.png
Static image detected, will now legofy and save as /lego_nexmo.png
Traceback (most recent call last):
  File "legofy/cli.py", line 17, in <module>
    main()
  File "/Library/Python/2.7/site-packages/click/core.py", line 700, in __call__
    return self.main(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/click/core.py", line 680, in main
    rv = self.invoke(ctx)
  File "/Library/Python/2.7/site-packages/click/core.py", line 873, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Library/Python/2.7/site-packages/click/core.py", line 508, in invoke
    return callback(*args, **kwargs)
  File "legofy/cli.py", line 14, in main
    legofy.main(image, brick=brick)
  File "/Library/Python/2.7/site-packages/legofy-0.0.1-py2.7.egg/legofy/__init__.py", line 131, in main
    makeLegoImage(baseImage, brick).save(newFilename)
  File "/Library/Python/2.7/site-packages/legofy-0.0.1-py2.7.egg/legofy/__init__.py", line 67, in makeLegoImage
    legoImage.paste(makeLegoBrick(brick, bp[0], bp[1], bp[2]), (x * width, y * height, (x + 1) * width, (y + 1) * height))
TypeError: 'int' object has no attribute '__getitem__'

"output" argument not used

@click.argument('output', default=None, required=False)
def main(brick, image, output):
    # [..]

.. but then it's not passed to anything (or used).

Error legofying a gif

screen shot 2015-11-02 at 6 24 33 am
Text:
Working on frame_0328.png Working on frame_0329.png Working on frame_0330.png Working on frame_0331.png convert -delay 4 -loop 0 ./tmp_frames/*.png /Users/k1lly/Pictures/lego_1.gif Traceback (most recent call last): File "/usr/local/bin/legofy", line 9, in <module> load_entry_point('legofy==0.0.1', 'console_scripts', 'legofy')() File "/Library/Python/2.7/site-packages/click-5.1-py2.7.egg/click/core.py", line 700, in __call__ return self.main(*args, **kwargs) File "/Library/Python/2.7/site-packages/click-5.1-py2.7.egg/click/core.py", line 680, in main rv = self.invoke(ctx) File "/Library/Python/2.7/site-packages/click-5.1-py2.7.egg/click/core.py", line 873, in invoke return ctx.invoke(self.callback, **ctx.params) File "/Library/Python/2.7/site-packages/click-5.1-py2.7.egg/click/core.py", line 508, in invoke return callback(*args, **kwargs) File "/Library/Python/2.7/site-packages/legofy-0.0.1-py2.7.egg/legofy/cli.py", line 13, in main legofy.main(image) File "/Library/Python/2.7/site-packages/legofy-0.0.1-py2.7.egg/legofy/__init__.py", line 133, in main call(command.split(" ")) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 522, in call return Popen(*popenargs, **kwargs).wait() File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__ errread, errwrite) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory server:Pictures k1lly$

ImageMagick - Right way to go ?

Hi,

I have a generall question regarding ImageImagick. Why did you decide to implement it? As far as I remember script worked without it.

I usually see external tools and bridges as a major design flow because of lack of flexibility and dependency on external provider. Perhaps there is a good reason for imagemagick?

Best regards

Error converting non-animated gif

I tried to convert this gif from libtiff package:

https://drive.google.com/file/d/0B-4dcK3QuA_LQzc2S3cxcEZYTUE/view?usp=sharing

and got this stacktrace:

$ legofy  ring.gif out.gif
Static image detected, will now legofy to /home/jightuse/code/projects/Legofy/out.png
Traceback (most recent call last):
  File "/home/jightuse//.local/bin/legofy", line 9, in <module>
    load_entry_point('legofy==0.0.1', 'console_scripts', 'legofy')()
  File "/home/jightuse/.local/lib/python2.7/site-packages/click-5.1-py2.7.egg/click/core.py", line 700, in __call__
    return self.main(*args, **kwargs)
  File "/home/jightuse/.local/lib/python2.7/site-packages/click-5.1-py2.7.egg/click/core.py", line 680, in main
    rv = self.invoke(ctx)
  File "/home/jightuse/.local/lib/python2.7/site-packages/click-5.1-py2.7.egg/click/core.py", line 873, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/jightuse/.local/lib/python2.7/site-packages/click-5.1-py2.7.egg/click/core.py", line 508, in invoke
    return callback(*args, **kwargs)
  File "/home/jightuse/.local/lib/python2.7/site-packages/legofy-0.0.1-py2.7.egg/legofy/cli.py", line 19, in main
    legofy.main(image, output=output)
  File "/home/jightuse/.local/lib/python2.7/site-packages/legofy-0.0.1-py2.7.egg/legofy/__init__.py", line 189, in main
    legofy_image(base_image, brick_image, output_path)
  File "/home/jightuse/.local/lib/python2.7/site-packages/legofy-0.0.1-py2.7.egg/legofy/__init__.py", line 149, in legofy_image
    make_lego_image(base_image, brick_image).save(output_path)
  File "/home/jightuse/.local/lib/python2.7/site-packages/legofy-0.0.1-py2.7.egg/legofy/__init__.py", line 58, in make_lego_image
    lego_image.paste(make_lego_brick(brick_image, bp[0], bp[1], bp[2]), (x * brick_width, y * brick_height, (x + 1) * brick_width, (y + 1) * brick_height))
TypeError: 'int' object has no attribute '__getitem__'

PIL Image Method Deprecation Error

I get the following error when running legofy from the command line: AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS'

After some quick Googling, it appears that this is an issue with PIL having deprecated this method.

Logo proposal

Hello @JuanPotato , today while exploring GitHub looking for interesting projects found yours and I would love to contribute by designing a logo for it. I'm a designer in development and an open source enthusiast. We would be working together to create the design that fits best. Of course it's totally free and you can quit whenever you want. In case you agree, please let me know any preferences you may have about colors, shapes, etc.

Kind regards.

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.