Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added image2dice_pattern/dice/21.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image2dice_pattern/dice/22.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image2dice_pattern/dice/23.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image2dice_pattern/dice/24.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image2dice_pattern/dice/25.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image2dice_pattern/dice/26.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image2dice_pattern/dice/31.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image2dice_pattern/dice/32.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image2dice_pattern/dice/33.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image2dice_pattern/dice/34.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image2dice_pattern/dice/35.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added image2dice_pattern/dice/36.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
from PIL import Image, ImageOps, ImageDraw

def diceImage(dicenumber,dicesize):
dim = Image.open("dice/" + str(dicenumber) + ".jpg")
dim = dim.resize((dicesize,dicesize), Image.ANTIALIAS)
return dim

dicew = 100

im = Image.open("/tmp/image.png")
dicew = 300
quality = 6 # minimum = 1, maximum = resolution of your dice image / dicesize
im = Image.open("image.png")
im = ImageOps.grayscale(im)
im = ImageOps.equalize(im)

diceh = im.height / im.width * dicew

dicesize = int(im.width / dicew)

nim = Image.new("L", (im.width, im.height), 'white')
nimd = ImageDraw.Draw(nim)
nim = Image.new("L", (im.width * quality, im.height * quality), 'white')
# nimd = ImageDraw.Draw(nim)

dices = []
for i in range(1, 7):
dim = Image.open("dice/" + str(i) + ".jpg")
dim = dim.resize((dicesize * quality, dicesize * quality), Image.ANTIALIAS)
dim = ImageOps.equalize(dim)
dices.append(dim)

for y in range(0, im.height-dicesize, dicesize):
for x in range(0, im.width-dicesize, dicesize):
Expand All @@ -26,11 +28,11 @@ def diceImage(dicenumber,dicesize):
thisSectorColor += im.getpixel((x+dicex, y+dicey))
thisSectorColor = thisSectorColor / (dicesize **2 )

nimd.rectangle(((x, y),(x+dicesize, y+dicesize)), thisSectorColor)
#nimd.rectangle(((x, y),(x+dicesize, y+dicesize)), thisSectorColor)
diceNumber = (255-thisSectorColor) * 5 / 255 + 1
#print (x, y, thisSectorColor, diceNumber)
print diceNumber,
im.paste(diceImage(diceNumber,dicesize), (x,y))
print
im.save("diceimage.png")
im.show()
# print diceNumber,
nim.paste(dices[diceNumber - 1], (x * quality, y * quality))
# print
nim.save("diceimage.png")
# nim.show()