メインコンテンツへスキップ
見出し画像

DrawThings(スクリプト1)

    DrawThingsのUIが変わってScriptという項目が表に出てきた。これは何?
    覗いてみるとサンプルが一つ入っていて、コメントが記載されている。

    //@api-1.0
    //
    // "Scripts" is a way to enhance Draw Things experience with custom JavaScript snippets. Over time,
    // we will enhance Scripts with more APIs and do neccessary modifications on the said APIs, but we
    // will also keep the API stable. In particular, you can mark your script with a particular API
    // version and it will make sure we use the proper API toolchain to execute the script even in
    // the future some of the APIs changed.
    //
    // Existing APIs:
    //
    // We currently provides three global objects for you to interact with: `canvas`, `pipeline` and `filesystem`.
    //
    // `canvas` is the object to manipulate the existing infinite canvas on Draw Things interface. It
    // supports the following methods:
    //
    // `canvas.boundingBox`: return the bounding box of existing images collectively on the canvas.
    // `canvas.clear()`: remove all images on the canvas, same effect as you tap on the "New Canvas" button.
    // `canvas.createMask(width, height, value)`: create a mask with a given size and fill-in value.
    // `canvas.currentMask`: return the current mask on the view, you can further manipulate the mask through `Mask` APIs.
    // `canvas.loadImage(file)`: load image from a file (a path).
    // `canvas.moveCanvas(left, top)`: move the canvas to a particular coordinate, these coordinates work as if the zoom scale is 1x.
    // `canvas.saveImage(file, visibleRegionOnly)`: save the image currently on canvas to a file.
    // `canvas.canvasZoom`: Set / get the zoom scale of the canvas.
    // `canvas.topLeftCorner`: return the coordinate the canvas currently at, these coordinates work as if the zoom scale is 1x.
    // `canvas.updateCanvasSize(configuration)`: extract the size from configuration object and then sync the canvas with that size.
    //
    // `pipeline` is the object to run the image generation pipeline. It supports the following methods:
    //
    // `pipeline.configuration`: extract the current configuration, whether it is on screen or after pipeline.run.
    // `pipeline.findControlByName(name)`: using the display name to find a particular control.
    // `pipeline.findLoRAByName(name)`: using the display name to find a particular LoRA.
    // `pipeline.prompts`: return prompt and negativePrompt currently on the screen.
    // `pipeline.run({prompt: null, negativePrompt: null, configuration: configuration, mask: null})`: run image generation through
    // this API. You can optionally provides prompt / negativePrompt, or it can take prompt from the screen. mask can be provided
    // optionally too and sometimes it can be helpful.
    //
    // `filesystem` provides a simple access to the underlying file system. Note that Draw Things is
    // sandboxed so we can only have access to particular directories within the user file system.
    //
    // `filesystem.pictures.path`: get the path of the pictures folder. It is the system Pictures folder on macOS, and a Pictures
    // folder under Draw Things within Files app for iOS / iPadOS.
    // `filesystem.pictures.readEntries`: enumerate all the files under the pictures folder.
    //
    // This script upscales the original image to 512x512 tiles and fixes the seams.
    // This script assumes the original image is at 1x zoom level.
    // The configuration parameters in this script may need tuning to improve final image.
    // Author: @Gooster

    せっかくなので、翻訳にかけてみる

     「スクリプト」は、カスタムJavaScriptスニペットでDraw Thingsの体験を向上させる方法です。時間が経てばスクリプトをより多くのAPIで強化し、そのAPIに必要な修正を加えていきますが、APIは安定したまま維持します。特に、スクリプトに特定の APIスクリプトを実行するために適切な API ツールチェインを使用するようにします。将来的にAPIの一部が変更されたとしても、スクリプトを実行するために適切なAPIツールチェインを使用するようにします。

    以下、翻訳を読みやすいように改行して表示しています。

    既存のAPI

    現在、3つのグローバルオブジェクトを提供している
    canvas、pipeline、filesystem である。

    canvas

     Draw Things インターフェース上の既存の無限キャンバスを操作するためのオブジェクトである。以下のメソッドをサポートしている。

    canvas.boundingBox

    キャンバス上の既存の画像のバウンディングボックスをまとめて返します。

    canvas.clear()

    キャンバス上の全ての画像を削除します。

    canvas.createMask(width, height, value)

    指定したサイズと塗りつぶし値のマスクを作成します。マスクをさらに操作するには `Mask` API を使用します。

    canvas.loadImage(file)

    ファイル(パス)から画像を読み込みます。

    canvas.moveCanvas(left, top)

    キャンバスを特定の座標に移動します。この座標はズーム倍率が1倍であるかのように動作します。

    canvas.saveImage(file, visibleRegionOnly)

    現在キャンバス上にある画像をファイルに保存します。

    canvas.canvasZoom

    キャンバスのズーム倍率を設定/取得します。

    canvas.topLeftCorner

    キャンバスの現在の座標を返します。この座標はズーム倍率が1倍であるかのように動作します。

    canvas.updateCanvasSize(configuration)

    設定オブジェクトからサイズを抽出し、そのサイズでキャンバスを同期します。

    pipeline

    画像生成パイプラインを実行するオブジェクトです。以下のメソッドをサポートしている

    pipeline.configuration

    画面上であるか、pipeline.runの後であるかに関わらず、現在の設定を抽出します。

    pipeline.findControlByName(name)

    表示名を使って特定のコントロールを探します。

    pipeline.findLoRAByName(name)

    表示名を使って特定のLoRAを見つける。

    pipeline.prompts

    画面に表示されているプロンプトとネガティブプロンプトを返す。

    pipeline.run({prompt: null, negativePrompt: null, configuration: configuration, mask: null})

    このAPIを通して画像生成を実行します。オプションでprompt/negativePromptを指定することができます。

    filesystem

    基礎となるファイルシステムへの単純なアクセスを提供する。Draw Thingsはユーザーファイルシステム内の特定のディレクトリにしかアクセスできないようにサンドボックス化されている。

    filesystem.pictures.path

    ピクチャフォルダのパスを取得する。macOSではシステムのPicturesフォルダ、iOS / iPadOSではFilesアプリ内のDraw Things配下のPicturesフォルダです。

    filesystem.pictures.readEntries

    ピクチャフォルダ配下のすべてのファイルを列挙する。

    以上翻訳

    オブジェクトは3つ。画像の生成そのものを操作できるものが公開されているようなので、使い方としては生成時の設定を自動的に変更させるということになりそう。

     
     
    徒然なる感じで書いています。クリエーターを名乗るほどの発信はできませんが、日々発見があるといいな。

    あなたへのおすすめ