This article mainly introduces the method of using Python for simple image processing and the example of Python automatically producing expression packs. It has a very good reference value. Let’s take a look at it with the editor.
As a data analysis Teachers should believe in a saying - "A picture is worth a thousand words." But what I want to talk about here is not data visualization, but a product form that is popular among all people-emoticon packs! ! ! !
EMoticon is not only a symbol, but also a culture - one of the driving forces to promote socialization and even social development, just like laziness. We insist that an excellent emoticon should be a work of art, a sudden burst of inspiration like a spring breeze overnight, a noisy emotional agitation, and an aspiration to sail across the sea. Pride is the small glorious victory that sees all the mountains in the world - it cannot be tolerated by coders using their usual linear thinking deconstruction with fixed forms, fixed processes, no beauty, no artistic changes and surprises. However, in the process of producing emoticons, it would be too low if we just mechanically import pictures into PS - change the text - and export, so we still keep these very low mechanized repetitive actions. Let the program do it.
I always thought that automatic image processing relied on JavaScript scripts to control PS or AI; later I discovered that Python can actually do some simple image processing, although it may not be as powerful as MATLAB. Therefore, for image processing, the complex parts are still completed manually in PS or AI, while simple processing can be completed using Python programs.
Before starting work, let us first pay tribute to the milestone figures in the emoji industry and thank them for vigorously promoting the significant progress of emojis in the historical trend. Their names will be talked about by the people for a long time. , their voices and smiles will last forever in people’s daily social interactions, and their outstanding contributions will forever be engraved on the monument of emoticon history!
(If royalties could be collected on expressions, then there would be no need to work so hard to play ball, film, or broadcast...)
Material preparation
Here we take the most widely circulated expression of Curator Jin on the Internet as the center, with the cute panda head as the background, and add text underneath to form an emoticon package.
Then use PS to process the image size, set the template size to 250*250, and crop the white edges of the expression.
Picture overlay
The first step is to overlay the expression onto the template. Note that our expression material is on a white background rather than transparent, so the position must be controlled well. , otherwise the outline will be covered.
from PIL import Image, ImageDraw, ImageFont img = Image.open(".\background.jpg") jgz = Image.open(".\jgz.jpg") img.paste(jgz,(73,42)) img.show()
In this way you will see the synthesized picture:
There is a blank space below this picture, which is for us to add text in the last step. of. come on, the devilish smile has appeared, and the next step is the final blow, are you OK?! Oh no, are you ready?!
Text Overlay
Although The core of emoticons is expressions, but a short and shocking line of text can often play the finishing touch that directly touches the soul.
draw = ImageDraw.Draw(img) ttfront = ImageFont.truetype('simhei.ttf', 24) draw.text((32, 190),"我的内心毫无波动\n 甚至还想笑",fill=(0,0,0), font=ttfront) img.show() img.save(".\Python生成的表情包.jpg")
In this way, a complete emoticon package is generated:
draw.text() is to input text into the layer, so you can Execute this command repeatedly to add multiple layers of text to the image.
You can also import multiple emoticons and multiple text lines, so that you can automatically produce emoticon packages on a large scale...
sublimation of the problem
Do you think it’s over here? Too young! Please think about this question:
The white space under the emoticon package is limited
The space occupied by Chinese, English and punctuation marks Different
If the text is too long, it needs to be wrapped; but if there are too many lines, the picture cannot fit
Therefore, When When a line that contains both Chinese and English and N-number of punctuation marks suddenly flashes in your mind to enhance the tone, how do you design an algorithm to find the appropriate font size, text insertion position, and where to wrap the text so that the text Can it be displayed in the center of a limited space and satisfy a certain look and feel?
Forget it, let’s end it here...
So, through this serious tutorial, we learned how to use Python for simple image processing, and even got a practical skill: automatically producing emoticons.
The most important thing is that what I often say, "Believe it or not, I will make a lot of your emoticons in batches in minutes" has finally become a reality...
[Related recommendations]
1. Special recommendation: "php Programmer Toolbox" V0.1 version download
3. Python object-oriented video tutorial
The above is the detailed content of Code examples for implementing emoticon packages in Python. For more information, please follow other related articles on the PHP Chinese website!

Python excels in automation, scripting, and task management. 1) Automation: File backup is realized through standard libraries such as os and shutil. 2) Script writing: Use the psutil library to monitor system resources. 3) Task management: Use the schedule library to schedule tasks. Python's ease of use and rich library support makes it the preferred tool in these areas.

To maximize the efficiency of learning Python in a limited time, you can use Python's datetime, time, and schedule modules. 1. The datetime module is used to record and plan learning time. 2. The time module helps to set study and rest time. 3. The schedule module automatically arranges weekly learning tasks.

Python excels in gaming and GUI development. 1) Game development uses Pygame, providing drawing, audio and other functions, which are suitable for creating 2D games. 2) GUI development can choose Tkinter or PyQt. Tkinter is simple and easy to use, PyQt has rich functions and is suitable for professional development.

Python is suitable for data science, web development and automation tasks, while C is suitable for system programming, game development and embedded systems. Python is known for its simplicity and powerful ecosystem, while C is known for its high performance and underlying control capabilities.

You can learn basic programming concepts and skills of Python within 2 hours. 1. Learn variables and data types, 2. Master control flow (conditional statements and loops), 3. Understand the definition and use of functions, 4. Quickly get started with Python programming through simple examples and code snippets.

Python is widely used in the fields of web development, data science, machine learning, automation and scripting. 1) In web development, Django and Flask frameworks simplify the development process. 2) In the fields of data science and machine learning, NumPy, Pandas, Scikit-learn and TensorFlow libraries provide strong support. 3) In terms of automation and scripting, Python is suitable for tasks such as automated testing and system management.

You can learn the basics of Python within two hours. 1. Learn variables and data types, 2. Master control structures such as if statements and loops, 3. Understand the definition and use of functions. These will help you start writing simple Python programs.

How to teach computer novice programming basics within 10 hours? If you only have 10 hours to teach computer novice some programming knowledge, what would you choose to teach...


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft