
Research
Security News
The Growing Risk of Malicious Browser Extensions
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
Official AIMG API client for Node.js. Allows you to generate dynamic images (PNG/GIF) using HTML templates. ✨
Official AIMG API client for Node.js. Allows you to generate dynamic images (PNG/GIF) using HTML templates. ✨
npm install aimg.js
# or
pnpm install aimg.js
# or
yarn add aimg.js
First, import the client and initialize it with your API key:
// filepath: example.js
const { AIMGClient } = require("aimg.js");
// or with ES Modules:
// import { AIMGClient } from "aimg.js";
const client = new AIMGClient({
apiKey: "YOUR_API_KEY", // Enter your API Key here
templatesPath: "./templates" // (Optional) Path to your templates folder, default: process.cwd()/templates
});
renderTemplate
)Renders an image using the specified template name. It reads the files (template.aimg.html
, session.aimg.json
, data.aimg.json
, animation.aimg.json
) from the template folder and sends them to the AIMG API.
You can see example templates in the templates folder.
// filepath: exampleRenderTemplate.js
const { AIMGClient } = require("aimg.js");
const fs = require("fs");
const client = new AIMGClient({ apiKey: "YOUR_API_KEY" });
async function renderMyTemplate() {
try {
// Render the 'level' template with default data.aimg.json
const result = await client.renderTemplate("level");
// Or render with custom data
const customData = {
user: {
name: "Custom User",
displayName: "Custom User | 99",
avatarUrl: "https://example.com/avatar.png",
avatarColor: "#ff0000"
},
levels: [ /* ... level data ... */ ]
};
const resultWithData = await client.renderTemplate("level", customData);
console.log("Render successful!", result.filename);
// Example: Save the image to a file
fs.writeFileSync(result.filename, result.buffer);
console.log(`Image saved as ${result.filename}.`);
} catch (error) {
console.error("Render error:", error);
}
}
renderMyTemplate();
render
)Renders an image by directly providing HTML content, configuration, and session settings.
// filepath: exampleRenderCustom.js
const { AIMGClient } = require("aimg.js");
const fs = require("fs");
const client = new AIMGClient({ apiKey: "YOUR_API_KEY" });
async function renderCustomHtml() {
const htmlContent = `
<!DOCTYPE html>
<html>
<head><title>Custom</title></head>
<body><h1>Hello, <%= it.name %>!</h1></body>
</html>
`;
const config = {
data: { name: "World" },
// Animation settings if needed
// animation: { ... }
};
const sessionConfig = {
type: "NoScriptStatic", // or "NoScriptAnimated"
// Profiles if needed
profiles: []
// profiles: [{ name: "TailwindCSS" }]
};
try {
const result = await client.render(htmlContent, config, sessionConfig);
console.log("Custom render successful!", result.filename);
// Example: Save the image to a file
fs.writeFileSync(result.filename, result.buffer);
console.log(`Image saved as ${result.filename}.`);
} catch (error) {
console.error("Custom render error:", error);
}
}
renderCustomHtml();
Each subfolder within the templatesPath
represents a template:
template.aimg.html
: The HTML structure of the image. Supports data injection using EJS-like <%= ... %>
syntax (via the it
variable).session.aimg.json
: Render session settings (RestSessionInstance
). Specifies the type
(NoScriptStatic
or NoScriptAnimated
) and the profiles
to use (e.g., TailwindCSS
, Unovis
, GSAP
).data.aimg.json
(Optional): Default data to be used in the template. This file is used if the data
parameter is not provided in the renderTemplate
call.animation.aimg.json
(Optional): Contains animation definitions if type
is set to NoScriptAnimated
in session.aimg.json
.Check the templates folder for example templates.
new AIMGClient(options)
Creates a new client instance.
options
: AIMGClientOptions
apiKey
(string, required): Your AIMG API key.rest?
: RestOptions
(Optional) Additional settings for the REST client (e.g., baseUrl
, timeout
, headers
).templatesPath?
: (string, Optional) Path to the folder containing templates. Default: path.join(process.cwd(), "templates")
.async renderTemplate(name, data?)
Renders a template.
name
(string): The name of the template folder within templatesPath
.data?
(Record<string, any>, Optional): Custom data to send to the template. If not specified, the template's data.aimg.json
file is used.Promise<{ buffer: Buffer, filename: string, content_type: "image/png" | "image/gif", statistics: any }>
async render(html, config, sessionConfig)
Renders custom HTML content.
html
(string): The HTML content to render.config
: RestRenderSessionOptions['config']
data
(Record<string, any>): Data to inject into the HTML.animation?
: Animation settings (if sessionConfig.type
is animated).sessionConfig
: RestSessionInstance
Specifies the session type and profiles.Promise<{ buffer: Buffer, filename: string, content_type: "image/png" | "image/gif", statistics: any }>
To build the project:
npm run build
This command compiles the TypeScript source code from src into JavaScript in the dist
folder.
This project is licensed under the GNU General Public License v3.0.
FAQs
Official AIMG API client for Node.js. Allows you to generate dynamic images (PNG/GIF) using HTML templates. ✨
We found that aimg.js demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
Research
Security News
An in-depth analysis of credential stealers, crypto drainers, cryptojackers, and clipboard hijackers abusing open source package registries to compromise Web3 development environments.
Security News
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.