Python Learning Notes-app icon shows the number of unread messages

Source: Internet
Author: User

In the case of Xiaomi's mobile phone system, when an app is installed with unread messages, the number of unread messages is displayed in the upper-right corner of the app icon. This article explains how to implement an icon to display the number of unread messages in the Python language. First of all, still need to use Python PiL library, about Linux how to install PIL library, please refer to this blog: http://blog.csdn.net/kevin_zhai/article/details/47720721, there are specific installation process. The principle of implementation is very easy to read the original icon directly with image. You can then insert the number of unread messages into the upper-right corner of the icon.

Script code such as the following:

#coding =utf-8import randomimport stringimport sysimport mathfrom PIL Import image,imagedraw,imagefont,imagefilter# Font location, different version number of the system will have different Font_path = "/USR/SHARE/X11/FONTS/TYPE1/C0611BT_.PFB" def gene_message_num (Pic_path,message_num, FontColor):    "    @pic_path: The position of the original avatar picture    @message_num: Number of unread messages    @fontcolor: The font color of the number of messages displayed    "    Image = Image.open (pic_path)    size = image.size    width,height = size #原始图片的宽和高    font = imagefont.truetype (font _path,30) #字体    draw = Imagedraw.draw (image)  #创建画笔    text = str (message_num)    font_width, font_height = Font.getsize (text)    Draw.text ((width-font_width, 0), text,            font=font,fill=fontcolor) #填充数字, position in upper right corner    Image.Save (' 1.jpg ') #保存图片if __name__ = = "__main__":    pic_path = "Qq.jpg"    message_num = 4    fontcolor = ( 255,0,0)    Gene_message_num (Pic_path,message_num,fontcolor)

Results show: The original icon and the script run and the icon see, because only simple implementation, the result is not very beautiful.




Python Learning Notes-app icon shows the number of unread messages

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.