Python Practice Book, one small program per day (0000)

Source: Internet
Author: User
in learning Python's lookup material, you find a collection of other people's Python topics. 0000 of the topics required to add a number in the upper right corner of a picture, the specific content can be clicked Https://github.com/Yixiaohan/show-me-the-code to view.
#功能: Enter the full address of the picture, and then enter the new generated picture name can produce a new number of pictures, where the font file I placed in the code the same folder
#-*-coding:utf-8-*-from

pil import Imagefont
from PIL import
pil import imagedraw

#输入图片的完整路径, open the picture
location = raw_input ("Please input the Location of the image: "
target = raw_input (" Please input the new name of target and you can enter to get the default Nam E: ")
image = Image.open (location)

#获得当前图片的大小, to set the font size
xsize, ysize = image.size Font
= Imagefont.truetype ("Arial.ttf", int (YSIZE/8))

#在图片上添加数字3
draw = Imagedraw.draw (image)
Draw.text ( 0.9*xsize, 0.1*ysize), "3", (255,0,0), font)

#根据输入的命名来设置新图片名字, the default setting is "formerly known as _new", formatted with the same
form = Location.split ( '.') [1]
If target = = "":
    new_location = Location.split ('. ') [0]
    Image.Save (new_location+ ' _new. ') +form)
Else:
    image.save (target+ '. ') +form)

The details of the Imagedraw module can be clicked Http://effbot.org/imagingbook/imagedraw.htm View
and the PIL module can be installed by clicking http:// pillow-cn.readthedocs.org/zh_cn/latest/installation.html View

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.