this.tempFile().then(tempPath => {
const wordLayer = gm(this.wordImgWidth, this.captchaHeight, 'transparent')
.fontSize(this.fontSize)
.fill(this.randColor())
.font(this.randFont())
.drawText(0, 0, word, 'Center')
.setFormat('png')
if (recognitionDifficulty !== 'easy') {
wordLayer.noise(this.randNoise())
.rotate('transparent', _.sample([1, -1]) * parseInt(Math.random() * 15, 10))
}
if (recognitionDifficulty === 'hard') {
wordLayer.affine([
_.random(.9, 1.1), _.random(-.1, .1),
_.random(-.1, .1), _.random(.9, 1.1),
_.random(-.2, .1), _.random(-.2, .1)
]).transform()
}
return wordLayer
.resize(this.wordImgWidth, this.captchaHeight)
.scale(this.wordImgWidth, this.captchaHeight)
.writeAsync(tempPath)
.return(tempPath)
})