A script thrown together for an Image-to-JSON-G-to-Image converter. Though this is a work-in-progress, it should be able to play nicely with other converters that follow the JSON-G spec.
Though you'll likely find that Jsong works better for you if you use only PNG, this script is guaranteed to work with anything ImageMagick is capable of reading, which means no need to waste your time converting to PNG first. :)
C:\Users\Michelle\Desktop\json-gerbil>ruby image-to-json-g.rb 00f.png
Converting to RGBA...
Slicing and dicing...
Determining most common color...
Converting to pixels...
Putting it all together...
Generating the JSON...
Saving your file...
Done. Took 4.790820837020874 seconds.
- The mini_magick gem.
- The json gem. (Unless you're using the large converter)
- ImageMagick installed in a place where Ruby can find it (with legacy tools on windows because mini_magick is a dumb)
- And because ruby is dumb, it doesn't check the current directory if you intend to just place the tools there. Uncomment line 55 of image-to-json-g.rb to fix this, but only if you are running the tools from the same directory.
- A fuckton of RAM if you plan to process complex images (that is, pictures with lots of colors)
because why do you give a fuck about efficiency if you're running this.- On that note, if you DO plan to process complex images, then I recommend you try using image-to-json-g-large.rb as this removes the JSON gem and all the hashing, which saves on RAM quite a bit and can help to avoid those pesky out-of-memory errors that the JSON gem can throw.
If you feel the need to run everything within a single directory, these files from a static portable windows download of ImageMagick worked for me for the usual PNG and JPG files:
convert.exe
identify.exe
colors.xml
delegates.xml
magic.xml
- These all will need to be placed in the same directory, and line 55 of image-to-json-g.rb will need to be uncommented.
Feel free to open an issue. Please include a log of what happened when you attempted to run the script, including the exception at the end.
- Samples to prove this works.
- Do the other way around (JSON-G to Image)
- Abstract the main method into something that can be called in an arbitrary process.
- Layer support.
- Make a common errors section in this readme.