Pandaaas (Pandas as a service)

Pandas are pretty cool 🐼, that along with useful tools that help your workflow as a developer. That's why I had a crack at building my own placeholder image service.

This is a project I worked on a very long time ago, my last commit was a while ago! 😅 Nonetheless I wanted to document this project for posterity.

A little bit about it.

A panda that changes when you refresh This image above 👆 has this url

Each time you request a random panda is given in the size specified in the URL:

URL
https://pandaaas.herokuapp.com/{x}/{y}

Some nerdy bits.

It's a pretty simple express application hosted on free instance of Heroku (you'll notice on first load it may take a while to spin up!)

On request the application grabs a random image and then throws it through a library called sharp which helps with image file conversion and resizing.

JS
const resizeImage = (path, format, width, height) => {
  const readStream = fs.createReadStream(path);
  let transform = sharp();
  if (format) {
    transform = transform.toFormat(format);
  }
  if (width || height) {
    transform = transform.resize(width, height);
  }
  return readStream.pipe(transform);
}

If you want to dig a little deeper.

Check out this project's repo on Github and have a dive around the code!

CopyrightKevin Borrill 2022

This site was last built at 15/02/2022 14:17:18
Built with: Gatsby & Tailwind CSS