如何使用 Node Jimp Blit 函式組合兩個點陣圖模式?
這個 **NodeJS – Blit()** 是一個內建函式,用於組合兩個點陣圖模式。它還可以使用布林函式將多個位圖組合成一個。
語法
blit(src, x, y, [srcx, srcy, srcw, srch])
blit() 引數的定義
**src** – 它將儲存用於 blit 的源影像。
**x** – 它將接收 x 的輸入以 blit 影像。
**y** – 它將接收 y 的輸入以 blit 影像。
**srcx** – 這是一個可選引數,它將接收 x 座標以裁剪源影像。
**srcy** – 這是一個可選引數,它將接收 y 座標以裁剪源影像。
**srcw** – 這是一個可選引數,它將接收寬度以裁剪源影像。
**srch** – 這是一個可選引數,它將接收高度以裁剪源影像。
輸入影像

使用 Node JIMP – BLIT()
在繼續使用 blit() 函式之前,請檢查以下語句是否已執行以設定環境。
npm init -y // 初始化 Node 環境
npm install jimp --save // 安裝 jimp 依賴項
建立一個 blit.js 檔案並將以下程式碼片段複製貼上到其中。
使用 node blit.js 執行程式碼。
**注意** – 方法名稱應與 JS 檔名匹配。只有這樣才能呼叫所需的方法。
示例
const Jimp = require('jimp') ;
async function blit() { // Function name is same as of file name
// Reading Image
const image1 = await Jimp.read
('/home/jimp/tutorials_point_img.jpg');
const image2 = await Jimp.read
('/home/jimp/tutorials_point_img.jpg');
image1.blit(image2, 100, 150)
.write('/home/jimp/blit.jpg')
}
blit(); // Calling the function here using async
console.log("Image is processed successfully");輸出

使用 Node JIMP – Blit() 帶可選引數
示例
const Jimp = require('jimp') ;
async function blit() {
// Reading Image
const image1 = await Jimp.read
('/home/jimp/tutorials_point_img.jpg');
const image2 = await Jimp.read
('/home/jimp/tutorials_point_img.jpg');
image1.blit(image2, 70, 100, 130, 30, 440, 80)
.write('/home/jimp/blit.jpg')
}
blit();
console.log("Image is processed successfully");輸出

廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP