<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          js2imagejs 源代碼壓縮成 ascii 字符畫

          聯(lián)合創(chuàng)作 · 2023-09-22 05:25

          js2image 是一個(gè)可以把js源代碼壓縮成一個(gè)ascii字符畫的源代碼的工具,它的特色是壓縮后的代碼仍可運(yùn)行,而不是簡(jiǎn)單的拼成最終的圖案。

          關(guān)于js2image的原理可以見我寫的這篇詳解文章:圣誕節(jié),把網(wǎng)站所有的js代碼都?jí)嚎s成圣誕樹吧。

          壓縮后的示例,親測(cè)可用

          http://f2e.souche.com/assets/js/lib/jquery-2.1.1.min.xmas.js

          另外,本項(xiàng)目resource目錄中有多個(gè)已經(jīng)跑通過(guò)的測(cè)試庫(kù)文件。

          壓縮效果如下:

          安裝依賴的系統(tǒng)模塊 graphicsmagick

          # Ubuntu$ sudo apt-get install graphicsmagick# Fedora$ sudo dnf install GraphicsMagick# OS X$ brew install graphicsmagick# Chocolatey (package manager for Windows)# (Restart of cmd/PowerShell is required)$ choco install graphicsmagick

          命令行工具使用方法

          執(zhí)行以下命令安裝全局命令:

          $ npm install js2image -g

          使用方法:

          # 直接在命令行里執(zhí)行此命令即可壓縮,默認(rèn)壓縮出一個(gè)xmas.js后綴的文件。# -s 源代碼路徑 必須的參數(shù)!# -r 是否反相圖像 可省# -i 指定使用的圖片的路徑,默認(rèn)使用 ./resource/tree.png 可省$ js2image -s ./resource/jquery.js# 新增支持打包一個(gè)文件夾內(nèi)所有js文件,慎用!不保證打包后的js100%運(yùn)行正常,請(qǐng)經(jīng)過(guò)人工測(cè)試確認(rèn)。$ js2image -s ./resource

          在Node.js中使用

          執(zhí)行以下命令安裝模塊:

          $ npm install js2image --save

          使用方法:

          var Js2Image = require('js2image');var image = './resource/tree.png';var source = './resource/jquery.js';var target = './target/xmas.js';var options = {};// 獲取結(jié)果的codevar sourceCode = fs.readFileSync(source);Js2Image.getCode(sourceCode, image, options).then(function (code) {  // code為生成的代碼
            console.log(code);
          })// 或者直接寫入文件Js2Image.writeToFile(source, image, target, options).then(function (code) {  // 生成的代碼已被寫入到文件target
            // code為生成的代碼
            console.log(code);
          });

          others

          有網(wǎng)友反饋某些電腦上會(huì)報(bào)錯(cuò),還沒搞清楚情況.

          onverting ./resource/release.js
          [Error: Could not execute GraphicsMagick/ImageMagick: gm "identify" "-ping" "-format" "%wx%h" "/usr/local/lib/node_modules/js2image/resource/tree.png" 
          this most likely means the gm/convert binaries can't be found]
          /usr/local/lib/node_modules/js2image/utils/image-to-struct.js:19
                var content = converted.replace(/\S\[0m/g,"").replace(/\n/g,"\",\n\"");
                                       ^
          
          TypeError: Cannot read property 'replace' of undefined

          如遇此種情況,執(zhí)行以下命令即可,至于是為毛,我也沒搞清楚.

          npm install -g replace
          
          瀏覽 21
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  人妻无码在线播放 | 欧美性爱手机版 | 免费h网站直播 | 最会潮吹的小护士露比来了上篇顶级色影 | 久久美国发布站 |