Options
All
  • Public
  • Public/Protected
  • All
Menu

Variable Injection

ImageScript variable injection

To inject variables (such as usernames, avatar URLs, etc.) into the ImageScript context, you can specify the args.inject object in the requests POST body. Variable injection supports both strings and numbers.


ImageScript variable injection

ImageScript
const image = Image.new(width, height, 0xff0000ff);
const avatar = Image.load(avatarURL).resize(height / 2, height / 2);
image.composite(avatar, width * 0.05, height / 2 - avatar.height / 2);
Injected variables
{
  "width": 1024,
  "height": 256,
  "avatarURL": "https://cdn.discordapp.com/avatars/687945863053443190/43022bb80ae031830866caacc18312de.png?size=1024"
}

Example POST body
{
  "args": {
    "text": "const image = Image.new(width, height, 0xff0000ff); const avatar = Image.load(avatarURL).resize(height / 2, height / 2); image.composite(avatar, width * 0.05, height / 2 - avatar.height / 2);",
    "inject": {
      "width": 1024,
      "height": 256,
      "avatarURL": "https://cdn.discordapp.com/avatars/687945863053443190/43022bb80ae031830866caacc18312de.png?size=1024"
    }
  }
}