The zodiac is auspicious, suitable for fishing~ Just use python to convert the picture into pixel wind~

Hello everyone, I am a red panda ❤

I have to say that the weather is really nice today.

neither cold nor hot~

The wind is blowing nicely~

The only downside is that I can't go out to play~ (woo woo wailing as a worker)

Please add image description


If you have any python-related error answers that you can't answer, or source code/module installation/women's clothing masters are proficient in skills, you can come here: ( https://jq.qq.com/?_wv=1027&k=2Q3YTfym ) or +V: python10010 ask me

Touch the fish, touch the fish...the inspiration comes!

How to convert an ordinary emoji into pixel style?

Next, I will use python to create a pixel wind with you~

Please add image description

Please add image description


Introduction to Tiler

Tiler, which means bricklayer, is to use various small elements as "tiles" to build a big picture [1].

Address: https://github.com/nuno-faria/tiler

The project presets a lot of "tiles":

There are LEGOs, plus signs, circles, @ signs, hearts, multipliers, wavy lines, horizontal and vertical bars, various grids from Minecraft, and paper clips.

In this article, I prefer to call them " pixel tiles ".

Please add image description
The project has already received 4.6k stars on GitHub​​​​​​​

Please add image description

Looking at the sample image, the pixel-style emoji mentioned at the beginning of this article should also be implemented.

Without further ado, install it first.

Clone and download the project, and then install the dependencies in requirements.txt.

git clone https://github.com/nuno-faria/tiler.git
 
pip install -r requirements.txt

The specific operation is shown in the following figure

C: \Users\Administrator>cd tiler
C:\[Users\Administrator|ti1er>pip install -r requirements.txt

Convert pixmap

Now demonstrate how to use Tiler to convert ordinary emoticons into pixel style.

After the previous operations, you can see the downloaded files and configurations locally.

Among them, the folder images contains project sample images, the folder tiles contains the tile directory, and the conf.py contains configuration files.

C:\Users\Administrator\tiler

Please add image description
I added a to-be-converted image - 333.png, but it doesn't matter if I put it in other directories, I just need to specify it in the next step.
Please add image description
In addition to the image to be converted, you also need to select a pixel tile. Only the line is suitable for the built-in pixel tile. We will use it to demonstrate first.
Please add image description
Among them, gen_line_h is placed in a horizontal line segment diagram.

Please add image description
To generate a pixmap, execute the following commands in the tiler directory:

python tiler.py ./images/333.png ./tiles/lines/gen_line_h/

Please add image description
During the execution process, there is a progress bar reminder. The image to be converted is small, and it is completed in a few seconds.

At this point in the tiler directory, a new image has been generated - out.png.

Please add image description
What about the Convert Pixel effect?

Achieved, but not fully realized, and a little bit of soul - not enough pixels.

Please add image description

customize

I'm guessing it's an issue with pixel tiles, the image above uses rectangular tiles.

But in the built-in directory, no square was found, so we need to customize the pixel block.

If you want a better pixel wind conversion effect, it is best to adjust the parameter configuration .

Let's talk about custom pixel blocks first.

custom pattern

First, create a new folder square2 in the directory tiles.

Put a custom pixel tile in it, I prepared a square (50x50 pixels).

The suggested color[2] is #F0F0F0.

C:\Users\Administrator\tiler\tiles\square2

Please add image description
Just having one tile is not enough, you need to use the script gen_tiles.py to generate a series of multi-color tiles.

Please add image description

custom parameters

Parameters can also be customized before generating pixel tiles.

By changing the code in conf.py, I adjusted values ​​like DEPTH.

  • DEPTH: The number of partitions for each color, the default value is 4.
  • COLOR_DEPTH: The number of colors the image contains, the default value is 32.
#GEN TILES CONFS
#number of divisions per color R,Gand B)#DEPTH =4 ->4*4*4=64 colors
DEPTH -6
# list of rotations, in degrees, to apply over the original imageROTATIONS - [e]
#############################
#TILER CONFS
#number of colors per imageCOLOR_DEPTH = 64
#tiles scales(1 = default resolution)RESIZING_SCALES -[0.5,0.4,0.3,0.2, 0.1]
# number of pixels shifted to create each box (tuple with (x,y))
# if value is None,shift will be done accordingly to tiles dimensions#PIXEL_SHIFT =(5,5)
PIXEL_SHIFT - None
#if tiles can overlapOVERLAP_TILES = False
#render image as its being builtRENDER = False

The author has annotated each configuration parameter in conf.py, and you can adjust it yourself when you use it.

custom effects

Next generate new pixel tiles.

Execute the command in the tiler directory:

Please add image description
Please add image description
Open the folder gen_square2, the pixel tiles of various colors have been generated.
Please add image description
The next step is to recreate the pixmap using the new tiles:

python tiler.py ./images/333.png ./tiles/square2/gen_square2/

Isn't it so simple! ! !

Download method: Blue Music Cloud (open the webpage to download directly):

https://sourl.cn/7F3X9j

Please add image description

Today's article ends here~

It looks like I'm about to be discovered

I'm Red Panda, see you in the next article (✿◡‿◡)

Please add image description

Guess you like

Origin blog.csdn.net/m0_67575344/article/details/126644119