Python PIL compositing picture, picture plus text

Source: Internet
Author: User

#-*-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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.