Created
March 24, 2022 11:46
-
-
Save nobonobo/e95b7f2511e7062544197ffa796ec5b3 to your computer and use it in GitHub Desktop.
macOSのsipsコマンドで画像に文字を入れる
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log(sips.arguments); | |
const caption1 = sips.arguments[3]; | |
const caption2 = sips.arguments[4]; | |
const w = sips.images[0].properties.PixelWidth; | |
const h = sips.images[0].properties.PixelHeight; | |
const canvas = new Canvas(w, h); | |
canvas.drawImage(sips.images[0], 0, 0); | |
canvas.font = "96pt Futura"; | |
canvas.textAlign = "left"; | |
canvas.textBaseline = "middle"; | |
canvas.fillStyle = "red"; | |
canvas.fillText(caption1, w * 0.01, h * 0.15); | |
canvas.strokeStyle = "white"; | |
canvas.lineWidth = 3; | |
canvas.strokeText(caption1, w * 0.01, h * 0.15); | |
if (caption2) { | |
canvas.fillStyle = "blue"; | |
canvas.fillText(caption2, w * 0.01, h * 0.3); | |
canvas.strokeStyle = "white"; | |
canvas.lineWidth = 3; | |
canvas.strokeText(caption2, w * 0.01, h * 0.3); | |
} | |
const output = new Output(canvas, "text.png"); | |
output.addToQueue(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
background.pngを用意しておき、2行の文字列を復路文字で描画します。
描画の場所やスタイル、色などはjs側を編集すればできます。