#-*-Coding:utf-8-*-from PIL import imagefrom PIL import imagefrom PIL import imagedrawfrom PIL import Imagefont
# load Basemap
# Set boundaries
# write in new picture content
# Save
# load Basemap base_img = Image.open (' e:/work/image/house_image/origin2.png ') # The area where p is required on the Basemap # is subject to the left margin (ieft, upper, right, lower) box = (0, 500, 750, 1200) # load new picture new_img = Image.open (' e:/work/image/house_image/back.png ') # Select an area of the new picture # Region_bottom = new_i Mg.crop ((0, 0, 304, 546)) # Load new picture full background Region_bottom = new_img# Paint Area Region_bottom = Region_bottom.resize ((box[2]-box[0], b OX[3]-box[1]) base_img.paste (region_bottom, Box) # can set save path Base_img.save (' E:/image/modify_image.png ')-----------------------------------------# Loading Words# set fonts Used font = Imagefont.truetype ("C:\Windows\Fonts\simhei.ttf", "+") content = ' Hello ' # draw draw = Imagedraw.draw (base_ IMG) # Set the text position/content/color/font, Chinese character coding, font garbled please change font try Draw.text ((260, 540), Text=content.decode (' UTF8 '), fill= (0, 0, 0), Font=font) DRA W = Imagedraw.draw (base_img) # View composite Picture # Base_img.show () # Save Picture Base_img.save (' result_image.png ')
Python PIL compositing picture, picture plus text