JPG Image renderer with Raspberry Pi and Minecraft Pi Edition

Using a Raspberry Pi, Minecraft PI edition, their Python API and PIL library (Python Imaging Library) I’ve build a sort of Minecraft image renderer.

The objective is load a JPG image into Minecraft world. The image must be less of 200px of width/height to avoid performance problems. A 200x200px image needs approximately up to 3 minutes to load.

The color mapping has been done using the 16 types of wool blocks with different colors.

I hope you like it!!

This slideshow requires JavaScript.

Here is the code:

# Script By Ferran Fabregas (ferri.fc@gmail.com)
import Image, sys, math
sys.path.append("./mcpi/api/python/mcpi")
import minecraft

# COLOR MAPPING
def colormap(pixel):
    white=(221,221,221)
    orange=(219,125,62)
    magenta=(179,80,188)
    lightblue=(107,138,201)
    yellow=(177,166,39)
    lime=(65,174,56)
    pink=(208,132,153)
    gray=(64,64,64)
    lightgray=(154,161,161)
    cyan=(46,110,137)
    purple=(126,61,181)
    blue=(46,56,141)
    brown=(79,50,31)
    green=(53,70,27)
    red=(150,52,48)
    black=(25,22,22)

    colors=(white,orange,magenta,lightblue,yellow,lime,pink,gray,lightgray,cyan,purple,blue,brown,green,red,black)

    thecolor=0
    finalresult=256*256*256
    for idx,color in enumerate(colors):
       result=math.fabs(color[0]-pixel[0])+math.fabs(color[1]-pixel[1])+math.fabs(color[2]-pixel[2])
       if result < finalresult:
          finalresult=result
          thecolor=idx
    return thecolor

# LOAD IMAGE FILE
im= Image.open(sys.argv[1])
pixels=im.load()
print im.size

# INIT MINECRAFT WORLD
mc=minecraft.Minecraft.create()
mc.postToChat("Welcome to Minecraft Image Render")
for x in range (-(im.size[0]/2),(im.size[0]/2)):
    for y in range (-(im.size[1]/2),(im.size[1]/2)):
        mc.setBlock(x,29,y,35,colormap(pixels[x+(im.size[0]/2),y+(im.size[1]/2)]))
        print "Print position:(%i,%i)"%(x+(im.size[0]/2),y+(im.size[1]/2))
mc.player.setTilePos(0,30,0)
print "RENDER FINISHED!!"

Download the source code here

Remember that one MC world must be running before start the script.

Posted in Minecraft, Pictures, Programming, Python, Raspberry Pi Tagged with: , , , ,
2 comments on “JPG Image renderer with Raspberry Pi and Minecraft Pi Edition
  1. TeCoEd says:

    This looks great, I will try tonight. Does this file run from the mcpi / API / python folder?

    • admin says:

      Hi! Can work anywhere (you can change the minecraft pi path) , but as it is, works from home folder, from where the mcpi folder is also uncompressed.

6 Pings/Trackbacks for "JPG Image renderer with Raspberry Pi and Minecraft Pi Edition"
  1. […] my new Pi Camera I improved the Minecraft JPG renderer script allowing to take pictures in real time using the Pi Camera and render it into […]

  2. […] Fabregas worked out a couple of months ago how to render .jpg images in the Minecraft world using Minecraft Pi Edition. Our logo seemed an obvious place to […]

  3. […] Fabregas worked out a couple of months ago how to render .jpg images in the Minecraft world using Minecraft Pi Edition. Our logo seemed an obvious place to […]

  4. […] the Minecraft Pi lottery wall is that you can create a minecraft wall with an image of your choice (using the Minecraft pi image render script) and let people break every block of the image sending messages via Twitter (based on the social […]

  5. […] Pi is great, but is very limited due their process capability, so I tried to improve the minecraft image renderer script using the Minecraft linux version (1.7.9), a Minecraft server (Bukkit or Canary mod, but Bukkit is […]

  6. […] my new Pi Camera I improved the Minecraft JPG renderer script allowing to take pictures in real time using the Pi Camera and render it into […]

Leave a Reply

Your email address will not be published. Required fields are marked *

*