Skip to content

Image to ANSI art conversion function for the OpenFaaS Platform in #golang

License

Notifications You must be signed in to change notification settings

johnmccabe/faas-img2ansi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

faas-img2ansi

Go Report Card

This repo contains an example FaaS function which uses the johnmccabe/img2ansi Go library to convert an image to an ANSI string.

Currently the following image formats are supported:

  • png
  • gif
  • jpeg

It demonstrates the use of a multi-stage build (available in Docker CE 17.06+) to build the Go binary seperately to the FaaS function image so as to keep the size as small as possible.

NOTE: Its recommended at this point to stick to small images as the resize capability hasn't been added yet.

Deploying the Function

Make sure you have deployed a FaaS stack to your cluster using the instructions on the FaaS repo.

Use the CLI (faas-cli)

Get the CLI

The faas-cli can be installed via brew install faas-cli or curl -sSL https://get.openfaas.com | sudo sh.

Now deploy the function as follows:

# faas-cli -action deploy -image=johnmccabe/faas-img2ansi -name=img2ansi -fprocess="/usr/bin/faas-img2ansi"
200 OK
URL: http://localhost:8080/function/img2ansi

Testing the Function

Now that the function is running in your FaaS environment you can test it from the command line by running:

$ curl -SL https://raw.githubusercontent.com/johnmccabe/faas-img2ansi/master/images/gopher.png > gopher.png

$ curl localhost:8080/function/img2ansi --data-binary @gopher.png

NOTE: as mentioned earlier, you should stick to small images for the moment (32x32 or so) as the function does not currently scale down large images.

Other ways to deploy the function

Using Curl

The function can be deployed using curl to hit the API endpoint directly:

# curl -s --fail localhost:8080/system/functions -d \
'{ 
   "service": "img2ansi",
   "image": "johnmccabe/faas-img2ansi",
   "envProcess": "/usr/bin/faas-img2ansi",
   "network": "func_functions"
}'

Using the UI

You can also create the function via the UI at http://localhost:8080/ui/, clicking the Create New Function link and entering the following data:

About

Image to ANSI art conversion function for the OpenFaaS Platform in #golang

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published