Skip to content

Upscaling Images

We’re going to walk through how to take a small, low-resolution image and upscale it to a higher resolution using the upscale endpoint. This is useful for sharpening generated thumbnails, restoring detail in old photos, or producing print-ready assets.

We’ll be using a 384x384 lighthouse photo as our input image:

upscale-input.jpg

Terminal window
# Create a project directory.
mkdir prodia-upscaling-images
cd prodia-upscaling-images

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

Your token is exported to an environment variable. If you close or switch your shell you’ll need to run export PRODIA_TOKEN=your-token-here again.

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!

The upscale endpoint accepts a single image and returns a larger version of it. The upscale config field controls the factor — 2, 4, or 8.

main.js
const { createProdia } = require("prodia/v2");
const fs = require("node:fs/promises");
const prodia = createProdia({
token: process.env.PRODIA_TOKEN,
});
(async () => {
// get input image
const inputBuffer = await (await fetch("https://docs.prodia.com/upscale-input.jpg")).arrayBuffer();
const job = await prodia.job({
type: "inference.upscale.v1",
config: {
upscale: 2,
},
}, {
inputs: [ inputBuffer ]
});
const image = await job.arrayBuffer();
await fs.writeFile("upscaled.jpg", new Uint8Array(image));
})();
Terminal window
node main.js
Terminal window
open upscaled.jpg

The 384x384 input is now a sharp 768x768 image. Edges around the lighthouse and rocks have crisper detail and the JPEG compression artifacts in the sky are gone:

upscale-output.jpg

For larger outputs, set upscale to 4 or 8. The endpoint returns the same dimensions multiplied by the chosen factor — for our 384x384 input, upscale: 4 produces a 1536x1536 image.

main.js
const { createProdia } = require("prodia/v2");
const fs = require("node:fs/promises");
const prodia = createProdia({
token: process.env.PRODIA_TOKEN,
});
(async () => {
// get input image
const inputBuffer = await (await fetch("https://docs.prodia.com/upscale-input.jpg")).arrayBuffer();
const job = await prodia.job({
type: "inference.upscale.v1",
config: {
upscale: 4,
},
}, {
inputs: [ inputBuffer ]
});
const image = await job.arrayBuffer();
await fs.writeFile("upscaled-4x.jpg", new Uint8Array(image));
})();
Terminal window
node main.js
Terminal window
open upscaled-4x.jpg

At 4x, the rocks gain individual texture and the clouds resolve into distinct shapes:

upscaled-4x.jpg

ParameterTypeValuesDefaultDescription
upscalenumber2, 4, 82How many times larger the output should be along each dimension.
GoalFactor
Sharpen a generated image without changing dimensions much2
Produce a print-ready or hero-banner asset from a thumbnail4
Maximum resolution for archival or large-format display8

Outputs scale quadratically — an 8x upscale of a 1024x1024 input produces an 8192x8192 image (around 67 megapixels), so prefer the smallest factor that meets your needs.