Skip to content

Transforming Images

Project Setup

Terminal window
# Create a project directory.
mkdir prodia-image-transformation
cd prodia-image-transformation

Install Node (if not already installed):

Terminal window
brew install node
# Close the current terminal and open a new one so that node is available.

Create project skeleton:

Terminal window
# Requires node --version >= 18
# Initialize the project with npm.
npm init -y
# Install the prodia-js library.
npm install prodia --save
Terminal window
# Export your token so it can be used by the main code.
export PRODIA_TOKEN=your-token-here

Create a main file for your project:

main.js
const { createProdia } = require("prodia/v2");
const prodia = createProdia({
token: process.env.PRODIA_TOKEN // get it from environment
});

You’re now ready to make some API calls!

Generate an image

main.js
const { createProdia } = require("prodia/v2"); // v2 :)
const fs = require("node:fs/promises"); // add this to imports at the top
const prodia = createProdia({
token: process.env.PRODIA_TOKEN, // get it from environment
});
(async () => {
// get input image
const sunnyDay = await (await fetch("https://upload.wikimedia.org/wikipedia/commons/thumb/b/be/Bliss_location%2C_Sonoma_Valley_in_2006.jpg/640px-Bliss_location%2C_Sonoma_Valley_in_2006.jpg")).arrayBuffer();
// run a flux dev generation
const job = await prodia.job({
type: "inference.flux.dev.img2img.v1",
config: {
prompt: "rainy landscape, 4k",
strength: 0.8
}
}, {
inputs: [ sunnyDay ]
});
const rainyDay = await job.arrayBuffer();
await fs.writeFile("rainy-day.jpg", new Uint8Array(rainyDay));
// open rainy-day.jpg
})();
Terminal window
node main.js
Terminal window
open rainy-day.jpg

Full Example

main.js
const { createProdia } = require("prodia/v2");
const fs = require("node:fs/promises"); // add this to imports at the top
const prodia = createProdia({
token: process.env.PRODIA_TOKEN, // get it from environment
});
(async () => {
// get input image
const sunnyDay = await (await fetch("https://upload.wikimedia.org/wikipedia/commons/thumb/b/be/Bliss_location%2C_Sonoma_Valley_in_2006.jpg/640px-Bliss_location%2C_Sonoma_Valley_in_2006.jpg")).arrayBuffer();
// run a flux dev generation
const job = await prodia.job({
type: "inference.flux.dev.img2img.v1",
config: {
prompt: "rainy landscape, 4k",
strength: 0.8
}
}, {
inputs: [ sunnyDay ]
});
const rainyDay = await job.arrayBuffer();
await fs.writeFile("rainy-day.jpg", new Uint8Array(rainyDay));
// open rainy-day.jpg
})();
Terminal window
node main.js