1.3.2 • Published 9 months ago

sharp-utils v1.3.2

Weekly downloads
-
License
ISC
Repository
github
Last release
9 months ago

sharp-utils

Node.jsの画像処理モジュールであるsharpのプラグイン的なモジュールです。

npm version

Installation

npm i sharp-utils

Documentation

その他細かいことはドキュメントを見て頂ければと思います。

Examples

import

import sharp from "sharp"
import { ... } from "sharp-utils" // import any function

circle

円の画像を生成します。

circle(100, {
    fill: {
        color: "tomato"
    },
    stroke: {
        color: "aqua",
        width: 20,
    }
}).toFile("circle.png")

結果

circle.png

サンプル画像

rect

長方形の画像を生成します。

rect(300, 200, {
    fill: {
        color: "#99d9ea"
    }
}).toFile("rect.png")

結果

rect.png

サンプル画像

roundedRect

角丸の長方形の画像を生成します。

roundedRect(300, 200, 20, {
    fill: {
        color: "#99d9ea"
    }
}).toFile("roundedRect.png")

結果

roundedRect.png

サンプル画像

regularPolygon

正多角形の画像を生成します。

regularPolygon(5, 100, {
    fill: {
        color: "#dac2ff"
    }
}).toFile("regularPolygon.png")

結果

regularPolygon.png

サンプル画像

createImage

空の画像を生成します。

createImage(400, 300, {
    r: 223, 
    g: 255, 
    b: 235,
    alpha: 1
}).toFile("createImage.png")

結果

createImage.png

サンプル画像

mask

画像にマスク処理をします。 グレースケール化されたマスク画像の深度(0-255)を参照して、対称の画像の透明度を変更します。

sample.png

サンプル画像

mask.png

マスク画像

let sampleImage = sharp("sample.png")
let maskImage = sharp("mask.png")

mask(sampleImage, maskImage).then(maskedImage => {
    maskedImage.toFile("masked.png")
})

結果

masked.png

マスク処理後の画像

TextToImage

ほぼtext-to-svgです。 元パッケージの仕様通り、ローカルのフォントを読み込んで画像出力できます。 オプションの仕様も同じです。

let text = new TextToImage("/fonts/KaiseiHarunoUmi-Regular.ttf", {
    fontSize: 120,
    attributes: {
        fill: "red"
    }
})

// 画像出力
text.getSharp("あいうえおアイウエオ安似宇江尾").toFile("font.png")

結果

font.png

フォント画像

1.3.2

9 months ago

1.3.1

9 months ago

1.3.0

9 months ago

1.2.1

9 months ago

1.2.0

12 months ago

1.1.1

12 months ago

1.1.0

12 months ago

1.0.0

12 months ago