Will you use Python's automatic emoticon generation function? Come and learn, from now on, fight the map invincible!

As a data analyst, you should believe in one sentence-"A picture is worth a thousand words". But what I want to talk about here is not data visualization, but a product form for the whole people-emoticons! ! ! !

Emoticons are not only a symbol, but also a kind of culture. It is one of the driving forces to promote social and social development, just like laziness.

We insist that an excellent emoticon package should be a work of art, an eruption of inspiration like a spring breeze, the noisy and miscellaneous emotions, and the lofty ambition to hang on the clouds and sail to the sea. Pride is the glorious victory with a glorious view of the mountains under the sky. It is not tolerable that the code farmer uses his usual fixed form, fixed process, no sense of beauty, no artistic changes and surprises, and straight-line thinking deconstruction.

However, in the process of producing emoticons, if you just mechanically import the picture into PS --> change the text --> export, it is too low, so these very low mechanized repetitive actions are still handed over to the program. do it.

I always thought that the automatic processing of images depends 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.

So for image processing, the complicated part is still done manually in PS or AI, and simple processing can be done with Python programs.

Before we start, let us pay tribute to the landmark figures in the emoji industry, thank them for their significant progress in the historical trend of emojis. Their famous names will be talked about by the people for a long time, and their voices and smiles will Enduring in people's daily social life, their outstanding contributions will always be engraved on the monument of emoji history!

(If the expression can be charged for copyright, then you don't have to work hard to play ball, film, broadcast...)

Material preparation

Here we focus on the most widely circulated expression of Curator Jin on the Internet, 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 border of the expression.

Picture overlay

The first step is to superimpose the expression on the template. Note that our expression material is white and not transparent, so the position should be controlled well, otherwise it will cover the outline.

draw = ImageDraw.Draw(img)ttfront = ImageFont.truetype('simhei.ttf',24)draw.text((32,190),"There is no fluctuation in my heart and I even want to laugh", fill=(0,0, 0), font=ttfront)img.show()img.save("./Python generated emoticon package.jpg")

Then you will see the synthesized picture:

There is a blank space below this picture, which is used for the last step of adding text. Come on, the magic 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 an emoticon is an emoticon, a short and shocking line of text can often serve as the finishing touch to the soul.

draw = ImageDraw.Draw(img)ttfront = ImageFont.truetype('simhei.ttf',24)draw.text((32,190),"There is no fluctuation in my heart and I even want to laugh", fill=(0,0, 0), font=ttfront)img.show()img.save("./Python generated emoticon package.jpg")

This generates a complete emoticon package:

Among them, draw.text() is to input text into the layer, so you can continue to execute this command to add multiple layers of text to the picture.

You can also import multiple emoticons and multiple text lines, so that you can automatically produce emoticons on a large scale...

Problem sublimation

Do you think it's over here? too young! Please think about this question for children's shoes: 1. The blank space under the emoji package is limited

2. The space occupied by Chinese and English and punctuation marks are different

3. If the text is too long, it needs to wrap; but if there are too many lines, the picture won’t fit

Therefore, when a line that contains both Chinese and English and N multiple punctuation marks to enhance the tone suddenly flashes in your mind, how to design an algorithm to find the appropriate font size, text insertion position, and where does the text wrap? , So that the text can be displayed in the center of a limited space, but also to satisfy a certain look and feel?

Forget it, let's end here...

So, through this serious tutorial, we learned how to use Python for simple image processing, and got a practical magical skill: automatic production of emoticons.

The most important thing is that the old man often said "Believe it or not, I will make a lot of your emoticons in batches in minutes", and finally become a reality...In this regard, I want to say that I am in love with Python afterwards! Because Python is so fun, too many directions!

Stainless Steel Black Leather Rod

Stainless Steel Black Leather Rod, 304 Stainless Steel Round Bar, Stainless Steel Flat Bar, Stainless Steel Threaded Rod

ShenZhen Haofa Metal Precision Parts Technology Co., Ltd. , https://www.haofametals.com