Skip to content

Instantly share code, notes, and snippets.

@nobonobo
Created March 24, 2022 11:46
Show Gist options
  • Save nobonobo/e95b7f2511e7062544197ffa796ec5b3 to your computer and use it in GitHub Desktop.
Save nobonobo/e95b7f2511e7062544197ffa796ec5b3 to your computer and use it in GitHub Desktop.
macOSのsipsコマンドで画像に文字を入れる
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();
@nobonobo
Copy link
Author

background.pngを用意しておき、2行の文字列を復路文字で描画します。
描画の場所やスタイル、色などはjs側を編集すればできます。

sips -j caption.js background.png “first line\!” “second line\!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment