| 181 | loc_x+=4 |
| 182 | |
| 183 | def CreateImage(data, width=32, height=32, rgba=False, invert=False, resize=[]): |
| 184 | img = Image.new( 'RGBA', (width,height), "white") |
| 185 | pixels = img.load() |
| 186 | |
| 187 | for i in range(len(data)): # for every pixel: |
| 188 | y = int(np.floor(i/width)) |
| 189 | x = i-y*width |
| 190 | #print("coord: "+str(x)+"_"+str(y)+":"+str(data[i])) |
| 191 | if rgba: |
| 192 | pixel = max(0, data[i]) |
| 193 | else: |
| 194 | pixel = [max(0, data[i]), max(0, data[i]), max(0, data[i]), 1] |
| 195 | if invert: |
| 196 | pixels[x,height-y-1] = (int(pixel[0]*255), int(pixel[1]*255), int(pixel[2]*255), 255) # set the colour accordingly |
| 197 | else: |
| 198 | pixels[x,y] = (int(pixel[0]*255), int(pixel[1]*255), int(pixel[2]*255), 255) # set the colour accordingly |
| 199 | |
| 200 | if len(resize)>0: |
| 201 | img = img.resize((resize[0], resize[1]), Image.NEAREST) |
| 202 | |
| 203 | return img |
| 204 | |
| 205 | def CarveDigit(pixels, digit, x, y, bg = (255, 255, 255, 255), color=(0, 0, 0, 255)): |
| 206 | #3x5 = 15pixels |