Ever want to share your code as an image? Code Nitro can do that. Code Nitro is lightweight, has minimal dependencies, and works online and offline.
Don't send your code to third parties, use Code Nitro.
You can install the nitro
command with pip.
pip install codenitro
The simplest usage is to simply pass a filename. Code Nitro will automatically syntax highlight it based on its extension.
nitro myfile.cpp
# creates myfile.png
nitro nitro.py --lines=40-54 --theme=desert
nitro nitro.py --lines=40-54 --theme=forest
nitro nitro.py --lines=40-54 --theme=moon
nitro nitro.py --lines=40-54 --theme=blue
nitro nitro.py --lines=40-54 --theme=cool
- Convert an entire file to an image via command line. By default, Code Nitro will save it in the same directory with the same name (but with .png).
nitro my_code.py [options]
- Convert only part of a file by using
--lines
. For example,--lines=5-10
will print lines 5 through 10, inclusive.
nitro my_code.py --lines=5-10
- Download a file from GitHub and convert it to an image by including the url in place of the filename.
nitro https://github.com/lukesalamone/code_nitro/blob/master/nitro.py
You can also import codenitro
and call the exposed code_to_image()
function programmatically.
from codenitro import code_to_image
image = code_to_image(
file_input="HelloWorld.java"
lines="23-34",
save=False # optionally return result rather than saving
)
print(type(image))
# "PIL.Image.Image"
Nitro comes with a few themes out of the box. Creating your own theme is easy as well. Just update your theme file in ~/.config/codenitro/themes.json