I am new to Python and tried to run the following code. I received the following error "IOError: cannot open resource"
. Is this due to the fact that some of the Image characteristics do not longer exist (e.g. Coval.otf), or is it potentially due to writing/reading restrictions? please let me know - many thanks, W
import numpy as np
from PIL import Image, ImageDraw, ImageFont
from skimage import transform as tf
def create_captcha(text, shear=0, size=(100,24)):
im = Image.new("L", size, "black")
draw = ImageDraw.Draw(im)
font = ImageFont.truetype(r"Coval.otf", 22)
draw.text((2, 2), text, fill=1, font=font)
image = np.array(im)
affine_tf = tf.AffineTransform(shear=shear)
image = tf.warp(image, affine_tf)
return image / image.max()
%matplotlib inline
from matplotlib import pyplot as plt
image = create_captcha("GENE", shear=0.5)
It's because Coval.otf
cannot be read, probably because it doesn't exist on your system, this is specified in the ImageFont doc
. I tried searching for the specific font and found no way of aquiring it. Look at @NewYork167's link if you must use the Coval
font.
Either way, to save yourself the trouble of installing fonts, you could just change the call to a font that exists on your system, use the one specified in the example of the docs:
font = ImageFont.truetype("arial.ttf", 15)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With