Current location - Health Preservation Learning Network - Slimming men and women - Project slimming, script batch compression pictures
Project slimming, script batch compression pictures
On the mobile side, we will use a lot of local pictures in the project, which will affect the size of our package to some extent. We definitely want our local pictures to be as small as possible, but the premise is that they cannot be distorted.

After the UI cuts the picture, I usually use TinyPNG to compress the picture before adding it to the project.

The compression effect is uneven, the naked eye can't feel the distortion, and a picture is compressed repeatedly, and finally it will be found that it can't be pressed down, which is quite good.

Disadvantages of online picture compression website

Up to 20 pictures, each with a maximum of 5M.

We must have at least 100 projects. If we have 20 projects and 20 projects, it will be very troublesome, and it also involves the problem of catalogue.

The above website compression method is only suitable for UI to develop a few pictures. Now, compress them, and then get the project. It is not suitable for batch compression.

Tinypng not only provides web page online compression, but also supports tool compression.

Tool compression, one-time free compression of 500 sheets, if there is a demand for one-time compression of more than 500 sheets, there is a charge.

/developer

So, how can tinypng ensure that you won't compress more than 500 sheets?

Apply for a key by email, and you can count the number of compressed sheets when compressing.

In other words, a mailbox can compress 500 pictures for free a month.

There are many platforms he supports.

Ruby,PHP,Node.js,Python,Java,。 WordPress plug-in

Here we use Python.

/developer/reference /python

1. 1. Install related packages.

If the installation of tinify fails, please refer to /p/3c7 1b9be3a5 1. I failed to install, about the source code.

1.2, used sparingly.

Just a few simple sentences above can be used to compress a picture. What we need is batch operation.

That is to find all the pictures to be compressed according to the directory and trample this method.

There are two Python scripts written here.

FindAllImages.py

Compressed image.py

If you want to detect the compression dragon, just run CompressImages.py directly.

1, directly compress the picture under Assets.xcassets with the above script.

2. The pictures in the project package are compressed separately.

3. Search the pictures existing in the project through scripts and compress them separately.

The compression effect of real project: 12.4MB before compression and 5.4M after compression.

Script address