Nodejs fixes png images processed by ipa,
Recently, a project encountered a requirement: parse the apk and ipa packages and upload the icons to the server.
Problem
The parsing and uploading process is relatively simple. I use JSZip to decompress apk and ipa, and then upload the icon in it to the server. However, when I use images on a webpage, the problem occurs. There is no problem with the icon in the apk, but the parsed image in ipa can be displayed normally in safari and cannot be displayed in any other browser.
Cause
Google found that Apple optimized the png image. For more information, see this article. In this article, we can find some useful information:
Apple uses PNGCursh open source library to crush png images inside iPA files。
Solution
As a front-end engineer, I want to use javascript to solve this problem. In fact, some people have already solved this problem in foreign countries. NodeJS-PNGDefry is fine. Unfortunately, it has not been maintained for too long and cannot run.
I can't find any available ones. I can only write one by myself. Therefore, node-pngdefry is available. Node-pngdefry has a clear function, that is, it uses Javascript to restore png images processed by Apple.
Node-pngdefry:
Command Line usage
Install:
$ npm install -g pngdefry
Then run:
$ pngdefry -i icon.png -o icon.new.png
Use in Node. js
$ npm install pngdefry --save-dev
var pngdefry = require('pngdefry');var path = require('path');var input = path.join(__dirname, 'icon.png');var output = path.join(__dirname, 'icon.new.png');pngdefry(input, output, function(err) { if (err) { return; } console.log('success');});
Test
$ npm test
Project address
Node-pngdefry
Articles you may be interested in:
- PNGHandler-use JavaScript to make PNG images transparent under IE (including background images)
- How to use JavaScript to implement an opaque png Image background in ie6
- Introduction to the PNG transparent JS plug-in of IE6
- Example of how JS solves png transparency in ie6
- The ThinkPHP watermark function is used to repair PNG transparent watermarks and increase the JPEG image quality.