How can I write text over an image, and overlay another image on it, in Python?

后端 未结 3 837
北海茫月
北海茫月 2021-02-04 12:38

I need to put some text over a PNG image in Python, I need to put another image too over the first one.

So I\'ll have a base image (the same for every image created), a

3条回答
  •  情书的邮戳
    2021-02-04 13:16

    I think opencv is easier to use:

    import cv2
    import numpy as np
    import matplotlib.pyplot as plt
    image = cv2.imread('xxx.png')  
    texted_image =cv2.putText(img=np.copy(image), text="hello", org=(200,200),fontFace=3, fontScale=3, color=(0,0,255), thickness=5)
    plt.imshow(texted_image)
    plt.show()
    

    Note that the original image may be changed, so I add np.copy to protect it. More details on the function is http://docs.opencv.org/2.4.8/modules/core/doc/drawing_functions.html?highlight=puttext#cv2.putText

    The fontFace can be referred to https://codeyarns.com/2015/03/11/fonts-in-opencv/

提交回复
热议问题