Nodejs fixes png images processed by ipa,

Source: Internet
Author: User

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.

Related Article

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.