Transform Stored Image

Programmatically transform images with powerful Filestack SDKs.

Try it yourself:

Use the Filelink class to transform images. Filelink allow over 50 transformations.

Terminal

npm install filestack-react tslib

FilestackTransformDemo.jsx
import { useMemo, useState } from "react";
import { Filelink } from "filestack-js";

// To run this demo,  Open ".env" file and replace "YOUR_API_KEY" with a vaild API key from Filestack DevPortal (https://dev.filestack.com/login/)
const filestackApiKey = process.env.VITE_FILESTACK_KEY;

// Replace "file_handle" with the handle of the file you want to transform.
const fileHandle = "file_handle";

export default function ImageTransformer() {
  const [width, setWidth] = useState("");
  const [height, setHeight] = useState("");
  const [fit, setFit] = useState("scale");

  const [format, setFormat] = useState("no");
  const [quality, setQuality] = useState("");
  const [compress, setCompress] = useState(false);

  const [flop, setFlop] = useState(false);

  const transformedUrl = useMemo(() => {
    const filelink = new Filelink(fileHandle, filestackApiKey);

    const w = Number(width);
    const h = Number(height);

    if (w > 0 && h > 0) {
      filelink.resize({
        width: w,
        height: h,
        fit,
      });
    }

    if (format !== "no") {
      const q = Number(quality);

      filelink.output({
        format,
        compress,
        quality: q >= 1 && q <= 100 ? q : 90,
      });
    }

    if (flop) {
      filelink.flop();
    }

    return filelink.toString();
  }, [width, height, fit, format, quality, compress, flop]);

  return (
    
Resize
setWidth(e.target.value)} />
setHeight(e.target.value)} />
Convert
setQuality(e.target.value)} />
setCompress(e.target.checked)} />
More Controls
setFlop(e.target.checked)} />
Transformed
); }

styles.css
#app {
  border: 1px dashed #000;
  padding: 15px;
}

.row {
  display: flex;
  gap: 20px;
  justify-content: center;
}

fieldset {
  margin-bottom: 15px;
}

.field {
  margin: 5px 10px;
}

input[type="number"],
select {
  width: 100%;
}

Terminal

npm install filestack-js tslib

HTML
Before trying this demo:
    • Open "index.html" and replace "file_handle" with the handle of the file you want to transform.
Resize
Width:
Height:
Fit:
Convert
Quality:
Compress:
Format:
More Controls
Flop:
logo

JavaScript
import "./styles.css";
import { Filelink } from "filestack-js";

const filestackApiKey = "Your_API_key";

document.getElementById("transform").addEventListener("click", function () {
  let target = document.getElementById("target");
  let handle = target.getAttribute("data-handle");
  const filelink = new Filelink(handle, filestackApiKey);

  let width = Number(document.getElementById("width").value);
  let height = Number(document.getElementById("height").value);
  if (width > 0 && height > 0)
    filelink.resize({
      width,
      height,
      fit: document.getElementById("fit").value,
    });

  let format = document.getElementById("format").value;
  if (format !== "no") {
    let quality = Number(document.getElementById("quality").value);
    let qualityOptions = {
      format,
      compress: document.getElementById("compress").checked ? true : false,
      quality: quality > 0 && quality <= 100 ? quality : 90,
    };
    filelink.output(qualityOptions);
  }

  let flopChecked = document.getElementById("flop").checked;
  if (flopChecked) filelink.flop();

  target.src = filelink.toString();
});

CSS

.warning {
  padding: 15px;
  background-color: orange;
  margin: 20px 0;
  border-radius: 5px;
}

#app {
  border: 1px dashed #000;
  padding: 15px;
}

.row {
  display: flex;
  gap: 20px;
  justify-content: center;
}

fieldset {
  margin-bottom: 15px;
}

.field {
  margin: 5px 10px;
}

input[type="number"],
select {
  width: 100%;
}

button {
  padding: 15px;
  background-color: #fff;
  border-radius: 10px;
  cursor: pointer;
  font-weight: bold;
  font-size: 18px;
}

button:hover {
  background-color: #eee;
}

Example

Resize
Width:
Height:
Fit:
Convert
Quality:
Compress:
Format:
More Controls
Flop:
Start building your own file upload solution today.

PREVIEW

Users can preview their uploaded files directly inside the File Picker.

CONNECT TO 20+ CLOUD DRIVES

Connect your app directly to AWS, Facebook, Dropbox, Instagram, and more.

PROGRESS BAR UPLOADS

Give your users confidence that their files are on the way to the right destination.

MULTI-FILE UPLOADS

Let your users upload multiple files at one time for speed and simplicity.

CUSTOM CSS

Filestack blends seamlessly into your website or app. Ask about white-labeling.

CLIENT-SIDE CROP

Users can crop files to perfection before sending them to your website or app.

UNLIMITED UPLOADING

Upload any file type, from any local or cloud source, at any scale.

WEBSITES & HTML

Filestack can even load web content from any public URL and capture the rendered page as an image. Perfect for generating screenshots, previews, or converting HTML-based content into other formats.

SECURE CLOUD STORAGE

Store uploads directly in your cloud storage for ease and accessibility.
“Being smart here, in my opinion, is seriously looking at Filestack to give you a fantastic uploading experience, while you spend your time on your product vision, not already-solved problems.”
— CHRIS COYIER, FOUNDER OF CSS-TRICKS & CODEPEN