Use emoji characters to form any Chinese character
Using emoji expressions to form Chinese characters or simple drawings is widely spread on WeChat and QQ, so I would like to try to make it myself.
For example, the picture below:
The realization that I thought of at the beginning The solution is: first convert Chinese characters into pictures with black characters on a white background, and then map the pictures into different characters based on grayscale values and print them on the terminal.
The former text-to-picture conversion is very easy to implement using common drawing libraries (such as python's PIL library); the workload is nothing more than slowly adjusting the layout during the implementation process to achieve your desired effect.
The latter is simple It’s just a mapping relationship: map the gray value of the pixels in the picture to a certain character; in this implementation, there are only two mapping relationships for pictures with black background and white characters, black characters correspond to the emoji characters to be replaced, and white background corresponds to blank .
The python implementation code of this part is as follows:
ascii_char = list('1234567890abcd ') # 任意多个字符,灰度值的映射区间 def select_ascii_char(r, g, b): ''' 在灰度图像中,灰度值最高为255,代表白色; 最低为0,代表黑色 ''' # 把RGB转为灰度值,并且返回该灰度值对应的字符标记 # 'RGB-灰度值'转换公式如下 gray = int((19595 * r + 38469 * g + 7472 * b) >> 16) # ascii_char中的一个字符所能表示的灰度值区间 unit = 256.0 / len(ascii_char) return ascii_char[int(gray/unit)]
select_ascii_char realizes mapping a pixel into a specific custom character char.
In the implementation of this function, ascii_char is simpler and only requires two characters That is: one is any given, and the other is a space.
So replace ascii_char with [u'❤️ ', u' ']
Due to the need to map the pixels of the image to characters that can be printed on the terminal, the display of the terminal The space is limited, so the image needs to be reduced and adjusted.
zh2emoji code has the corresponding code download on my github. If you are interested, you can fork it to achieve more customized functions you want.
Show
I have N multiple ways of writing the word "fennel":
print image2print(word2image(u'茴'), u'❤️ ') print image2print(word2image(u'茴'), u'W ') print image2print(word2image(u'茴'), u'茴', width=40)
The output results are as follows:
More output:
Extended
based on z h2emoji,self Implemented an extension that may be useful: demo_show_animation.py.
It can print out a sentence in sequence on the terminal, using emoji or other characters you decide.
For example, if you try to execute python ./demo_show_animation.py Like Just click like, and an animation displaying text will be executed in the terminal. The text displayed is what you just entered.
If you can persist till this point, have you thought of some interesting ways to play? Welcome to participate. . Programming is a kind of fun, and code is a medium for realizing some mental ideas; programmers write code, just like writers write words, it is a habit.
In the future, I may plan to play an animation composed of emojis in the terminal (such as the loading animation of Buka Girl)

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



According to reports on January 26, according to foreign technology media emojipedia, in the iOS 17.4 Beta 1 update released today, in addition to major improvements such as sideloading and third-party app stores for testing in 27 EU countries, Apple has also added several new Emoji. The iOS 17.4 Beta 1 update adds phoenix, lime, smiling faces shaking their heads up and down, and a series of character emoticons that point the way, from the Emoji 15.1 update proposed by Unicode in September 2023. The complete Emoji are attached as follows: This update adds a total of 118 Emojis, including 6 new Emojis and 4 gender-neutral family Emojis. In addition, there are 6 existing character expressions

Emoji emoticons are the latest input method function added to Win10 Education Edition. Many cute emoticons make chatting less boring. However, some users will pop up this interface when using shortcut keys. Today I will show you how to turn off emoji in Win10 Education Edition. introduce. How to turn off emoji1 in Win10 Education Edition. First, you need to right-click the input method on the right side of the taskbar below. 2. Select Settings in the pop-up option box to enter the language setting interface. 3. Select the "Keys" option in the interface and scroll to the bottom to find "Open Emoticons and Symbols Panel", where you can turn off emoji expressions. 4. If other input methods are installed, you can enter the "Settings and Language" interface from Windows settings, and then select

Huawei emoji input method: 1. Huawei mobile phones come with an emoji keyboard. You can switch to this keyboard to enter emoji when entering text; 2. Where you need to enter emoji, long press the input box, and then select "Enter" "Method Settings", in the input method settings, you can find and select the emoji input method that comes with the system; 3. You can download and use a third-party emoji keyboard, and then browse and select the emoji you want to use on the keyboard. .

Apple has officially launched iOS 15.4 and iPadOS 15.4 Beta 1 to the public, version 19E5209h. The official update notes list many changes, including the addition of new features. Support for masks Face ID Apple has added “Mask Face ID” in iOS 15.4. The iPhone will authenticate users by identifying the unique characteristics of the area around the eyes when wearing a mask. Note that users must use iPhone 12 or above to use this feature. Adding 112 new Emoji expressions iOS 15.4 Beta 1 officially supports Emoji 14. Add to it

Solution to the garbled mysql emoji code: 1. Check the mysql table encoding through the "show create table test ENGINE=InnoDB DEFAULT CHARSET=utf8mb4" command; 2. Set the reading encoding to "utf8mb4" through "set names utf8mb4;"

Apple pushes iOS15.4Beta5 and iPadOS15.4Beta5 to developers. It is estimated that this may be the final Beta. It is likely to enter the RC stage next week, and the official version will be released before mid-March. AirTag anti-tracking function The new version of iOS 15.4 introduces the AirTag and FindMy anti-tracking functions previously announced by Apple. Now they have been introduced in Beta 4, adding warning messages and adjusting the "unknown accessories detected" warning during pairing design. Siri’s new voice option For American users, iOS15.4Beta4 has added the fifth Siri voice (file name: Quinn).

Apple officially releases the much-anticipated official version of iOS 15.4. What people are most concerned about this time is the "Mask FaceID" function. This feature allows iPhone 12 or above models to unlock like normal FaceID after enabling the FaceID function. And it is not limited to unlocking, but can also be used in ApplyPay, AppStore, and logging into Apps. The situation is exactly the same as the FaceID we use every day. Added 112 new Emoji expressions iOS15.4 officially supports Emoji14. 37 new image Emojis have been added, and 75 different skin colors are supported, which means there are 1

Apple officially launches iOS15.4 and iPadOS15.4Beta3 to developers, version 19E5225g. The official update notes list many changes, including the addition of new features. Support mobile data download and update In the past, updating iOS required WiFi, but the new version of iOS15.4Beta3 has added the "mobile data download" function, which means that iOS can be updated even without WiFi. Supporting Mask FaceID Apple has added “Mask FaceID” in iOS 15.4. The iPhone will authenticate users by identifying the unique characteristics of the area around the eyes when wearing a mask. Note, users must use an iPhone
