Nodejs fix the PNG image processed by IPA _node.js

Source: Internet
Author: User

A recent project encountered a demand: Parse apk and IPA package, and then upload the icon inside the server.

Problem

Parse upload process is relatively simple, I use Jszip to apk and IPA for decompression, and then find inside the icon upload to the server. However, when I use a picture in a Web page, the problem arises. There is no problem with the icon in the APK, but the images that are parsed in IPA can be displayed normally in Safari and cannot be displayed in any other browser.

Reason

Google later found that it is Apple to optimize the PNG image, read this article (view), in the article we can learn some useful information:

Apple uses Pngcursh open Source Library to crush PNG images inside IPA files.

Solution

As a front-end engineer, I would like to use JavaScript to solve this problem. In fact, before someone abroad has to solve, Nodejs-pngdefry is OK, but this too long did not maintain, has not run up.

Can not find available, I have to do their own clothing, to write one. So there was node-pngdefry. Node-pngdefry's function is clear: Use JavaScript to restore the PNG image processed by Apple.

Node-pngdefry usage is simple 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

Node-pngdefry

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.