Pygame to implement text transfer picture program code

Source: Internet
Author: User

Text to the picture is actually like PHP in the Verification Code program, the following I come to introduce you to the students.

text2pic.py

The code is as follows Copy Code

# coding: Utf-8
 
Import pygame
Pygame.init ()
 
# All available system Fonts
# Print pygame.font.get_fonts () br>  
# font name, size
Font = Pygame.font.SysFont (' Microsoftyahei ', +)
 
# characters, whether to open anti-aliasing, foreground color, background color &N Bsp
Text1 = font.render (U ' according to relevant laws ', True, (0,0,0), (255,255,255))
Pygame.image.save (Text1, ' text1.jpg ')
  br> # with transparent words do not set the background color
Text2 = font.render (U ' This page cannot display ', True, (0,0,0))
Pygame.image.save (Text2, ' text2.png ')
 
# Combination
W, h = text1.get_size ()
surface = Pygame. Surface ((w, 2*h))
Surface.fill ((255, 255, 255)) # Because of the default background black
Surface.blit (Text1, (0, 0))
Surface.blit (Text2, 0, h))
Pygame.image.save (surface, ' all.png ')

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.