nodejs fixes png images processed by ipa

  • 2020-12-20 03:29:10
  • OfStack

A recent project encountered a need to parse the apk and ipa packages and then upload the icon packages to the server.

The problem

The process of parsing the upload was relatively simple. I used JSZip to unzip apk and ipa, and then uploaded the icon found inside to the server. However, the problem arose when I used images on the web. For icon in apk, there is no problem, but for images parsed in ipa, they can be displayed normally in safari and cannot be displayed in any other browser.

why

After Google, we found that It was Apple that optimized the png image. Take a look at this article (see) for details. We can learn some useful information in this article:


Apple uses PNGCursh open source library to crush png images inside iPA files . 

The solution

As a front-end engineer, I hope to solve this problem with javascript. In fact, it has been solved by someone abroad before, es31EN-ES32en is just ok. Unfortunately, it has not been maintained for a long time, so it can't run.

I couldn't find one, so I had to write one myself. So node-ES36en. node-pngdefry has the explicit function of using Javascript to restore png images processed by Apple.

node-pngdefry usage is simple and supports both the command line and the regular ES45en.js:

Command line usage

install:


$ npm install -g pngdefry

then run:


$ pngdefry -i icon.png -o icon.new.png

Used in ES59en.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

The project address

node-pngdefry


Related articles: