Home >Web Front-end >JS Tutorial >Nodejs repairs png pictures processed by ipa_node.js
I recently encountered a need in a project: parse apk and ipa packages, and then upload the icons inside to the server.
Question
The parsing and uploading process is relatively simple. I use JSZip to decompress the apk and ipa, and then upload the icon found inside to the server. However, the problem arises when I use images in web pages. There is no problem with the icons in the apk, but the pictures parsed in the ipa can be displayed normally in safari, but cannot be displayed in any other browser.
Reason
After Google, I found that Apple has optimized png images. Please read this article (view) for details. We can learn some useful information in the article:
Apple uses PNGCursh open source library to crush png images inside iPA files。
Solution
As a front-end engineer, I hope to use javascript to solve this problem. In fact, someone abroad has already solved it before. NodeJS-PNGDefry can do it. Unfortunately, this has not been maintained for too long and it can no longer run.
I couldn’t find one available, so I had to make enough food and clothing myself and write one myself. Hence node-pngdefry. The function of node-pngdefry is very clear, which is to use Javascript to restore png images processed by Apple.
node-pngdefry is very simple to use and supports command line and regular Node.js:
Command line usage
install:
$ npm install -g pngdefry
then run:
$ pngdefry -i icon.png -o icon.new.png
Using 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