Skip to content

Instantly share code, notes, and snippets.

@fsmunoz
Created April 20, 2017 21:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fsmunoz/ec950806b9014f6305ec28372fdde329 to your computer and use it in GitHub Desktop.
Save fsmunoz/ec950806b9014f6305ec28372fdde329 to your computer and use it in GitHub Desktop.
### THE JPEGINATOR
### Openwhisk bmp->jpeg conversion using OpenWhisk
### Author: Frederico Munoz <frederico.munoz@pt.ibm.com>
### Date: APR 2017
### License: Eclipse Public License v1.0
## Load the image-related libraries
library(bmp)
library(pixmap)
library(base64enc)
library(httr)
library(jsonlite)
## Read and encode
read_filename <- file("lisboa_arco.png", "rb")
b64 <- base64encode(read_filename)
## Set the REST endpoint - change for your own
url <- "https://openwhisk.ng.bluemix.net/api/v1/web/frederico.munoz%40pt.ibm.com_Default/default/jpeginator.json"
## The POST request itself, passing the image as a JSON argument
req <- POST(url, body = list(image = b64), encode = "json")
## Parsing the request
j <- fromJSON(content(req, "text"))
## Let's see what we have here
str(j)
## Write file (which is now a JPEG, courtesy of the JPEGINATOR!!!1!
## ...
writeBin(base64decode(j$body), "lisboa2.jpg")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment