OpenFaaS is cloud native and has Prometheus metrics built-in - so you can run it on any hardware and at scale. There is no need to worry about being locked-in to a complicated architecture, set of tools or a particular cloud vendor.įind out more about our project by heading over to and be sure to Star the project on GitHub to show your support. If you fancy a challenge - why not try editing the function to apply a "Polaroid" style to your pictures? You can even customise the text by passing an addition HTTP header like this: $ curl -H "X-Caption: I'm running Serverless on my own terms" -data-binary > whale-text.jpg Here's an example of what you can do once the function is deployed: $ curl -data-binary > whale-text.jpg Here's an example of a function which can print text (you supply) on top of an image: Any ImageMagick commands can be pasted into the "fprocess" variable and re-built to make an image-processing pipeline that can scale as a Serverless function in your cluster. What else can I do with ImageMagick?Ĭheckout the ImageMagick homepage here. You can now invoke it again: $ cat whale.jpg | faas-cli invoke upscale-image > whale-bigger.jpgĪs expected - the resulting size is 2296 × 1500 and 537KB. $ faas-cli deploy -filter=upscale-image -f samples.yml Now we must re-build and re-deploy the functions: $ faas-cli build -filter=upscale-image -f samples.yml How do you do something different?Įdit the fprocess variable in sample/imagemagick/Dockerfile and put 200% instead of 50% - and you can now scale-up thumbnails to double their original size.Įdit the samples.yml file and pick a new Docker image name and function name for your function: upscale-image: Read more about the function watchdog here. # Alternatively use ADD (which will not be cached by Docker builder)ĮNV fprocess="convert -resize 50% fd:1" Sample/imagemagick/Dockerfile FROM alpine:3.6 The fwatchdog (fork watchdog) binary is placed into a container as the entrypoint and is responsible for enforcing timeouts and reading/writing values to and from your function via pipes. Well for every request that comes into the function we fork ImageMagick, feed in the bytes of the larger image via STDIN and then read the response over STDOUT and send that back to the caller. So now we can see the resulting image at 50% of the size - 817 × 500 and 115KB on disk. If your server is remote, you can also pass the -gateway flag. Now let's shrink it to 50%: $ cat whale.jpg | faas-cli invoke shrink-image > whale-small.jpg If you checkout the image, you'll see it's around 1148 × 750 and 131KB in size. Let's grab a photo from Pexels who provide royalty-free images and then try it out: $ curl -sSL "" > whale.jpg The ImageMagick sample is deployed as shrink-image. Shrink-image will reduce any image to 50% of its size. Now let's deploy the shrink-image function: $ faas-cli deploy -f samples.yml -filter=shrink-image On Mac you can type in brew install faas-cliĬheck it worked with faas-cli version Deploy the samplesĬlone the CLI from GitHub which contains several samples, including ImageMagick: $ git clone If you're on Linux or Windows type in: $ curl -sL | sudo -E sh Once you've deployed OpenFaaS, we now need to install the FaaS CLI tool: If you already have a cluster ready or Docker on your laptop then this takes less than 60 seconds to deploy. Pre-reqsįollow the guide for setting up OpenFaaS Docker Swarm or Kubernetes below. Build serverless functions using Docker containers and deploy onto Kubernetes and Docker Swarm. OpenFaaS is Serverless, but on your terms. In this blog post I want to give you a fresh take on ImageMagick and deploy it as a scaleable serverless function with OpenFaaS and Kubernetes, or Docker Swarm. There's not much you cannot do with it, but one of the most common use-cases I've seen is reducing image size to generate thumbnails. ImageMagick is an age-old tool (27 years old today!) for Linux which is used for image manipulation and generation.
0 Comments
Leave a Reply. |