import bpy D = bpy.data # Specify your image here, open it inside Blender Image Editor panel image_file = 'raspberrypi_logo_mini_blanc.png' img = D.images[image_file] pixels = list(img.pixels) grouped_list = [pixels[ipx:ipx+4] for ipx in range(0, len(pixels), 4)] # Get width and height of image (in pixel) w = width = img.size[0] h = height = img.size[1] print("------LENGTH------") print( len(img.pixels)//4) print("------PIXEL------") print(pixels) print("---GROUPED-PIXEL---") print(len(grouped_list)) # Create LIST of GRID XY value rowColList=[] for i in range(height): for j in range(width): rowColList.append(i) rowColList.append(j) # SPLIT the LIST of XY origList = rowColList splitList = [origList[i:i+2] for i in range(0,len(origList),2)] for number in range(len(grouped_list)): # separate RGBA into each own variables r = grouped_list[number][0] g = grouped_list[number][1] b = grouped_list[number][2] a = grouped_list[number][3] # separate XY coordinate x=splitList[number][0] y=splitList[number][1] # create cube at location XY bpy.ops.mesh.primitive_cube_add(location=(x-width/2, y-width/2, 0)) selectedObject = bpy.context.selected_objects selectedObject[0].name = 'pixelcube.%s' % number selectedObject[0].scale = 0.45, 0.45, 0.45 # add material with RGB color as sampled for every pixel mat = bpy.data.materials.new('pixelColor') mat.diffuse_color = (r,g,b) mat.diffuse_shader = 'LAMBERT' mat.diffuse_intensity = 1.0 #mat.emit=0.5 bpy.context.object.data.materials.append(mat) print ('PixelCube {number} created at:'.format(number=number), x, y, ', with RGB color', r, g, b)