Original link: https://nexmoe.com/1GSAPJA.html
Today I found some animated emoticons in PNG format on the Internet . I won’t tell you that I stole the emoticons from LINE , so I learned that they are in APNG format. Since WeChat and QQ do not support APNG, we converted APNG to GIF. After converting APNG to GIF, we found that it could only be played once on WeChat, which raised the question of how to batch modify the number of GIF loops.
So I’m going to give a brief introduction to APNG. And provides an online tool that can batch convert APNG to GIF, but the tool cannot achieve infinite loop. So I shared a method to modify the number of GIF loops in batches, using two different implementation methods: Node.js and batch scripts. It is convenient for Node developers and ordinary users using Windows to process batches directly.
What is APNG?
APNG (Animated Portable Network Graphics) is a bitmap animation extension of PNG, which can achieve dynamic picture effects in PNG format. APNG has advantages over GIF in terms of picture quality and detail performance, and as more and more browsers support APNG, it is expected to become one of the standards for the next generation of dynamic graphics. The main differences are as follows:
-
Picture quality: GIF supports up to 256 colors and does not support Alpha transparency channel, which results in poor quality of GIF on colorful pictures and pictures with translucent effects. APNG can support higher quality pictures, including more colors and Alpha transparent channels, making the animation effect more delicate.
-
Composition principle: Both APNG and GIF are animations composed of multiple frames, but the composition principle of APNG allows supernatural backward compatibility. The first frame of APNG is a standard PNG image. Even if the browser does not recognize the animation data behind the APNG, it can display the first frame without any obstacles. And if the browser supports APNG, it can play the subsequent frames to achieve animation effects.
-
Browser support: Starting from Chrome 59, the Chrome browser begins to support APNG, allowing most browsers to display APNG animations. Only IE browser does not support APNG.
For more information, please refer to: https://xtaolink.cn/268.html
APNG batch to GIF
This tool can convert APNG to GIF in batches, but it cannot loop infinitely.
https://cdkm.com/cn/png-to-gif
Batch modify GIF to infinite loop
bat (ordinary users please use this method)
Here’s how to use a batch script (.bat) to achieve the same functionality:
|
Please replace C:\path\to\directory
with your actual directory path. Save the above code as a .bat
file and double-click to run it. The script will traverse all .gif
files in the specified directory and modify them.
Note that batch scripts have relatively limited capabilities and cannot read binary files directly. The above script simulates reading the file contents by reading the first line of the file. When modifying a file, it writes the modified data directly to the file without performing binary operations. This approach may not work in all situations, and there may be performance issues especially when working with large files. If more complex binary file processing is required, consider using another programming language or tool to implement it.
Node (the method used by Nexmoe)
|
Note that the above code uses Node.js’s file system module ( fs
) to read and write files. Additionally, ./path/to/directory
needs to be replaced with the actual directory path. Before executing this script, make sure Node.js is installed.
This script will traverse all files in the specified directory in batches and call the unlimitedGifRepetitions
function to modify the files with the .gif
suffix. Modified data will be written back to the original file. In the console output, you can see information about each file that was modified or any error messages that occurred.
For more information, refer to: https://www.b612.me/golang/232.html
This article is reproduced from: https://nexmoe.com/1GSAPJA.html
This site is only for collection, and the copyright belongs to the original author.