import random
from PIL import ImageFont
from PIL import ImageDraw
from PIL import ImageColor
from PIL import Image
from matplotlib import pyplot

if __name__ == "__main__":
    # input the srcImg
    srcPath = r'C:\Users\Administrator\Desktop\input.jpg'
    outPath = r'C:\Users\Administrator\Desktop\output.jpg'
    whitePath = r'C:\Users\Administrator\Desktop\white.png'
    blackPath = r'C:\Users\Administrator\Desktop\black.png'
    img = Image.open(srcPath)
    whiteImg = Image.open(whitePath)
    blackImg = Image.open(blackPath)

    print(whiteImg.size)
    print(blackImg.size)

    # create BLOCK
    startBlock = (7, 2, 2, 6)
    print(startBlock[2])
    texturePic = ImageDraw.Draw(img)
    font = ImageFont.truetype(r"C:\Windows\Fonts\ARIALUNI.TTF", size=40)
    xNum = 0  # -> 7-1
    yNum = 0  # -> 5-1
    dayPtr = 1
    realDay = 1
    while yNum < 5:
        while xNum < 7:
            if startBlock[2] < dayPtr < 31:
                if random.random() > 0.25:
                    img.paste(blackImg, (
                    int(167 - blackImg.size[0] / 2 + 124 * xNum), int(597 - blackImg.size[1] / 2 + 116.7 * yNum)))
                    numText = u"8"
                    numText = str(realDay)
                    if realDay < 10:
                        texturePic.text((157 + 124 * xNum, 568 + 116.7 * yNum), numText, font=font, fill='white')
                    else:
                        texturePic.text((146 + 124 * xNum, 568 + 116.7 * yNum), numText, font=font, fill='white')
                    realDay += 1
                else:
                    img.paste(whiteImg, (
                    int(170 - blackImg.size[0] / 2 + 124 * xNum), int(597 - blackImg.size[1] / 2 + 116.7 * yNum)))
                    numText = u"8"
                    numText = str(realDay)
                    if realDay < 10:
                        texturePic.text((157 + 124 * xNum, 568 + 116.7 * yNum), numText, font=font, fill='black')
                    else:
                        texturePic.text((146 + 124 * xNum, 568 + 116.7 * yNum), numText, font=font, fill='black')
                    realDay += 1
            xNum += 1
            dayPtr += 1
        xNum = 0
        yNum += 1

    # OLD create TEXTURE
    # texturePic = ImageDraw.Draw(img)
    # font = ImageFont.truetype(r"C:\Windows\Fonts\ARIALUNI.TTF", size=40)
    # xNum = 0  # -> 7-1
    # yNum = 0  # -> 5-1
    # while xNum < 7:
    #     while yNum < 5:
    #         texturePic.text((157 + 124*xNum, 568 + 116.7*yNum), u"8", font=font, fill='white')
    #         yNum += 1
    #     yNum = 0
    #     xNum += 1

    # output test
    img.save(outPath)
    pyplot.imshow(img)
    pyplot.show()
    # img.show()

import random
from PIL import ImageFont
from PIL import ImageDraw
from PIL import ImageColor
from PIL import Image
from matplotlib import pyplot

if __name__ == "__main__":
    # input the srcImg
    srcPath = r'C:\Users\Administrator\Desktop\input.jpg'
    outPath = r'C:\Users\Administrator\Desktop\output.jpg'
    whitePath = r'C:\Users\Administrator\Desktop\white.png'
    blackPath = r'C:\Users\Administrator\Desktop\black.png'
    img = Image.open(srcPath)
    whiteImg = Image.open(whitePath)
    blackImg = Image.open(blackPath)

    print(whiteImg.size)
    print(blackImg.size)

    # create BLOCK
    startBlock = (7, 2, 2, 6)
    print(startBlock[2])
    texturePic = ImageDraw.Draw(img)
    font = ImageFont.truetype(r"C:\Windows\Fonts\ARIALUNI.TTF", size=40)
    xNum = 0  # -> 7-1
    yNum = 0  # -> 5-1
    dayPtr = 1
    realDay = 1
    while yNum < 5:
        while xNum < 7:
            if startBlock[2] < dayPtr < 31:
                if random.random() > 0.25:
                    img.paste(blackImg, (
                    int(167 - blackImg.size[0] / 2 + 124 * xNum), int(597 - blackImg.size[1] / 2 + 116.7 * yNum)))
                    numText = u"8"
                    numText = str(realDay)
                    if realDay < 10:
                        texturePic.text((157 + 124 * xNum, 568 + 116.7 * yNum), numText, font=font, fill='white')
                    else:
                        texturePic.text((146 + 124 * xNum, 568 + 116.7 * yNum), numText, font=font, fill='white')
                    realDay += 1
                else:
                    img.paste(whiteImg, (
                    int(170 - blackImg.size[0] / 2 + 124 * xNum), int(597 - blackImg.size[1] / 2 + 116.7 * yNum)))
                    numText = u"8"
                    numText = str(realDay)
                    if realDay < 10:
                        texturePic.text((157 + 124 * xNum, 568 + 116.7 * yNum), numText, font=font, fill='black')
                    else:
                        texturePic.text((146 + 124 * xNum, 568 + 116.7 * yNum), numText, font=font, fill='black')
                    realDay += 1
            xNum += 1
            dayPtr += 1
        xNum = 0
        yNum += 1

    # OLD create TEXTURE
    # texturePic = ImageDraw.Draw(img)
    # font = ImageFont.truetype(r"C:\Windows\Fonts\ARIALUNI.TTF", size=40)
    # xNum = 0  # -> 7-1
    # yNum = 0  # -> 5-1
    # while xNum < 7:
    #     while yNum < 5:
    #         texturePic.text((157 + 124*xNum, 568 + 116.7*yNum), u"8", font=font, fill='white')
    #         yNum += 1
    #     yNum = 0
    #     xNum += 1

    # output test
    img.save(outPath)
    pyplot.imshow(img)
    pyplot.show()
    # img.show()

# input the srcImg # create BLOCK # -> 7-1 # -> 5-1 # OLD create TEXTURE # texturePic = ImageDraw.Draw(img) # font = ImageFont.truetype(r"C:\Windows\Fonts\ARIALUNI.TTF", size=40) # xNum = 0  # -> 7-1 # yNum = 0  # -> 5-1 # while xNum < 7: #     while yNum < 5: #         texturePic.text((157 + 124*xNum, 568 + 116.7*yNum), u"8", font=font, fill='white') #         yNum += 1 #     yNum = 0 #     xNum += 1 # output test # img.show()