JuanPotato / Legofy

Make images look as if they are made out of 1x1 LEGO blocks
MIT License
3.16k stars 189 forks source link

ImageMagick - Right way to go ? #62

Closed ITCave closed 9 years ago

ITCave commented 9 years ago

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

JuanPotato commented 9 years ago

Imagemagick was in the script since the beginning, it is the tool that the script used to make gifs, it is only not needed when making static images legofied. You can see it in the first commit

If you can find a good working way to make gifs in pillow, I will gladly switch it in place of imagemagick.

ITCave commented 9 years ago

Ok , I'll check if there is anything suitable

JuanPotato commented 9 years ago

I have seen that you can save a gif in PIL to be animated, but last time I tried it greatly messed up. try this and tell me what happens

i = Image.open("test.gif")
i.save("test_pillow.gif", save_all=True)
ITCave commented 9 years ago

I've made some test and the whole animated gif thing is not achieveable by PIL alone. I've made some reasearch and put together working solution here: https://github.com/JuanPotato/Legofy/pull/71

jmhungdev commented 9 years ago

Hi when I ran legofy image.jpg it returns Could not find the MAGICK_HOME environment variable. I already install imagemagick 64-bit in my window what's the next step to resolve the issue?

thank you,

JuanPotato commented 9 years ago

@hungmeenhong Just wait a bit, I'm merging things now.

JuanPotato commented 9 years ago

@hungmeenhong running legofy image.jpg (static images) should work with the latest commits. If it is not working please try to see where imagemagick is installed and add the environment variable by using setx MAGICK_HOME C:/path/to/imagemagick

jmhungdev commented 9 years ago

@JuanPotato now it says Brick asset "C:\Users\jhung\AppData\Local\Continuum\Anaconda\lib\site-packages\legofy-0.0.1-py2.7.egg\legofy\assets\bricks\1x1.png" was not found.

JuanPotato commented 9 years ago

@hungmeenhong you are running python setup.py install and then legofy image.jpg right? Also does that directory exist when you use file explorer? or to what level does it exist?

jmhungdev commented 9 years ago

Right, so I copy paste the setup.py and legofy folder under Anaconda file, wrote python setup.py install legofy image.jpg

this is the returning error message: Brick asset "C:\Users\jhung\AppData\Local\Continuum\Anaconda\lib\site-packages\legofy-0.0.1-py2.7.egg\legofy\assets\bricks\1x1.png" was not found.

When I check "lib" folder I couldn't find it. There's one "Lib" folder, but I don't think they are the same. @JuanPotato

JuanPotato commented 9 years ago

@hungmeenhong the "Lib" folder should still work, it works on my laptop. Are you sure you are copying everything into the folder?

jmhungdev commented 9 years ago

@JuanPotato I think I got it right now, so assets folder wasn't in legofy. So I copy the assets from your original legofy folder into it, and it worked! thanks!

niroyb commented 9 years ago

Looks like PIL supports saving gifs : http://pillow.readthedocs.org/en/3.0.x/handbook/image-file-formats.html#saving-sequences

JuanPotato commented 9 years ago

@niroyb see the fourth comment in this issue.

ITCave commented 9 years ago

@JuanPotato I've made some tests what save_all behaves weird and sometimes inconsistent. E.g. It sometimes misses 1 frame and I'm not sure why.

I've also found some threads like this one : https://github.com/python-pillow/Pillow/issues/1355

I'll give it another try today and give you heads up.

ITCave commented 9 years ago

Ok, so I took a deeper look at Pillows GifImageFile class and it won't be that easy to adopt native Pillow classes . First of all , single frames are accessible via ImageSequence class which is basically a wrapper for more direct seek() function (GifImagePlugin.py). GifImageFile object (in this case PIL.Image) is always represented by a single frame. seek() function only replaces the frame representation. More than that - it does it each time by reading the file on the bit level.

GifImageFile also doesn't have any easily accessible function that would reassemble set of singles images into Gif animation. There is whole SAVE_ALL architecture based on drivers for particular Image formats but it requires more time to work with and probably a customized GifImageFile mutation. And well, thats what https://github.com/CasualBeer/images2gif library basically is.

I going to read more about PIL but afaik there is no "Image-Sequence" object that is saveable.