Home > Web Front-end > JS Tutorial > body text

Nodejs repairs png pictures processed by ipa_node.js

WBOY
Release: 2016-05-16 15:15:09
Original
1261 people have browsed it

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。
Copy after login

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
Copy after login

then run:

$ pngdefry -i icon.png -o icon.new.png
Copy after login

Using in Node.js

$ npm install pngdefry --save-dev
Copy after login
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');
});

Copy after login

Test

$ npm test
Copy after login

Project Address

node-pngdefry

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template