示例#1
0
 def __init__(self, filenameEx, trainingText=None, trainingSize=None, isFadeGeneral=True, isFadeShallow=True, isLeakDown=True, leakDeg=0, leakHeight=0, spotMaxNum=15, spotNumVariance=5, spotBaseColor=(193, 151, 85), spotColorVariance=20, spotBlur=0, spotNoise=0, paperColor=(255,255,255), rotDeg=0):
     self.isInkFadeGeneral = isFadeGeneral
     self.isInkFadeShallow = isFadeShallow
     self.isInkLeakDown = isLeakDown
     self.filenameEx = filenameEx
     self.filename = os.path.splitext(filenameEx)[0]
     self.pathEx = './static/created/' + filenameEx
     self.path = './static/created/' + self.filename
     # self.text = self.readText(imageNameEx=self.filenameEx)
     if trainingText:
         self.text = trainingText
     else:
         self.text = _util.readText(self.filenameEx)
     self.formatter = ft.ImageFormatter()
     if trainingSize:
         self.formatter.size = trainingSize
     self.bgGenerator = ImageBackgroundGenerator(paperColor, trainingSize)
     self.spotter = ImageSpotter(self.bgGenerator.img(), int(spotMaxNum), int(spotNumVariance), spotBaseColor, int(spotColorVariance), int(spotBlur), int(spotNoise), trainingSize)
     self.rotDeg = rotDeg
     self.canvas = _util.getTransparentImage(self.formatter.size[0], self.formatter.size[1])
     self.canvasDr = ImageDraw.Draw(self.canvas)
     self.leakDeg = int(leakDeg)
     self.leakHeight = int(leakHeight)
     self.output = None
示例#2
0
    def printWtRotNScl(self, leakdDeg):
        bg = self.spotter.renderIm().convert('RGBA')
        self.draw = ImageDraw.Draw(bg)
        lineOriginY = self.formatter.marginTop
        lineOriginX = self.formatter.marginLeft
        boxOriginX = lineOriginX
        boxOriginY = lineOriginY
        leakVerOffset = 10
        for line in textwrap.wrap(self.text, width=self.formatter.char_num_per_line):
            line = line.replace(' ', '')
            boxOriginX = lineOriginX
            for char in line:

                box = self.formatter.font.getsize(char)
                charWidth = box[0]
                charHeight = box[1]
                charIm = _util.getTransparentImage(charWidth, charHeight)
                charDr = ImageDraw.Draw(charIm)
                charDr.text((0,-10), char, self.formatter.textColor, font=self.formatter.font)
                # Crop / Ink leak down
                offset = self.formatter.font.getoffset(char)
                cropPos = _util.getCropPos(box, offset, leakdDeg)
                pastePos = _util.getPastePos(box, offset, leakVerOffset)
                cropped = charIm.crop(cropPos)
                charIm.paste(cropped, pastePos)

                # Rotate and scale
                scaleW = _util.randomfWith(1.0,1.2)
                scaleH = _util.randomfWith(1.0,1.2)
                charIm = charIm.rotate(0, expand=1).resize((int(charWidth), int(charHeight)))
                bg.paste(charIm, (boxOriginX, boxOriginY), charIm)

                boxOriginX += charWidth
            boxOriginY += self.formatter.lineHeight
        _util.saveImage(bg, fullpath=(self.path+'_lkg'+'_lkd' + '.png'))
        return 'created/' + self.filename + '_lkg' + '_lkd' + '.png'