Created
April 20, 2017 21:23
-
-
Save fsmunoz/ec950806b9014f6305ec28372fdde329 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### THE JPEGINATOR | |
### Openwhisk bmp->jpeg conversion using OpenWhisk | |
### Author: Frederico Munoz <[email protected]> | |
### 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