A Python program to convert images into NFP images for display on ComputerCraft monitors inside of Minecraft. Inspired by this program. Feel free to open issues or PRs.
The nfp.py
module can convert between standard image formats and NFP. When converting from image to NFP, it uses Pillow to quantize the image, reducing its color palette to the 16 available ComputerCraft colors.
convert_nfp.py
is a simple command-line utilty that uses this module, made because why not?
"NFP" is a simple text-based 16-color image format used by ComputerCraft's paint program and the paintutils API. Each pixel is represented by a one-digit hex value from 0-f (decimal 0-15) corresponding to an index into the 16-color ComputerCraft color palette. Each row is terminated by a newline.
A black/white 4x4 checkerboard NFP image looks like this:
f0f0
0f0f
f0f0
0f0f
python3 -m pip install -r requirements.txt
Converting from image -> NFP:
python3 convert_nfp.py image.png
(Images are automatically resized to 164x81, the maximum resolution for 8 by 6 (max size) scale 0.5 ComputerCraft monitors, before conversion, unless the --skip-resize
, --resize-width
, or --resize-height
arguments are specified.)
Converting from NFP -> PNG:
python3 convert_nfp.py image.nfp
Converting from NFP -> JPEG:
python3 convert_nfp.py image.nfp --format=JPEG
Converting multiple files at once:
python3 convert_nfp.py image1.nfp image2.nfp [...]
(Special thanks to Commandcracker for this feature!)
See convert_nfp.py -h
for full usage info. See the Pillow docs for supported conversion formats.
After converting an image to NFP, you can upload it to pastebin, and use paintutils.drawImage()
to fetch and display it in-game. Example program that downloads an NFP from pastebin (like this one) using the paste ID passed in as an argument and displays it on a connected monitor:
local args = {...}
local paste_id = args[1]
shell.run("delete image.nfp") --delete file if it already exists
shell.run("pastebin", "get", paste_id, "image.nfp") --fetch NFP image from pastebin at given paste_id
print("Drawing...")
local old_term = term.current()
local mon = peripheral.find("monitor") --find and attach to monitor
mon.setTextScale(0.5)
term.redirect(mon)
term.clear()
--draw image through paintutils
local image = paintutils.loadImage("image.nfp")
paintutils.drawImage(image, 0, 0)
term.redirect(old_term)
print("Done")
This example program has been posted to pastebin, so you can just use the below to display an example image:
pastebin get MuZxYKrQ disp_nfp
disp_nfp yjXanZ0j
Tested on Python 3.