This service takes a Base64 encoded DataURI via a POST request, and responds with a URL representing the decoded image. It's useful as a Javascript API to take a screenshot of an HTML5 canvas and convert it to a URL that can then be shared on social networks.
The way we originally envisioned using this was for a project that generated custom canvas images. We wanted to share a screenshot of the canvas on Facebook. So we used this in combination with the following project to convert the canvas to an image and wrap it in a page with opengraph META tags in real time. See the following complementing project:
https://github.com/aminariana/opengraph-meta-describer
The main production instance for your use:
As of July 26, 2017, the database grew too large to maintain records for free. I have modified code to only keep the latest 10K uploads, so that I can still keep it below the free tier. If you want your image resources to remain in cache permanently, either host your own service or offer me a fee so I can pay database costs to Heroku.
Author:
Documentation site:
The main API is the following path, used in POST requests:
The POST request parameters accepted:
- 'image[data_uri]': The 64 bit encoded string representing the image
Data URI example for PNG (Panda face):
iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYxIDY0LjE0MDk0OSwgMjAxMC8xMi8wNy0xMDo1NzowMSAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwL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M8MNY7gFgtLTChcZcPzT9/HS3/evarjorqeF3v407Dl49OSpJbeUvHPq+MeLJkydjw5PY7zLMQ00k2xA1Z1bpAHDPcQ3ZDK+vv0hGRIx4AYh9yaNGIVTxw/hYnPbO4zFmIPbcv5P7xzG7N5236Hi62anZuSORVdH0xAj+Kbsgf7sGHbJAbazAVfAFSSn5qK1qR6nT37aUXX3H7gZaSQJ8AZ1kAoua8buvcf2zZ2as9jpSHCkZxVSWgZJcWygWBlMOCo00egwoTku5XqchCLu9uTUPAKvw3cnjnmW3fPHhbTURMIVzBjsgf7Bz18ae+LNbRvfzcrJTym6bi7lrBc9wU6qjjodMOGnBgNz5XQ4U+hxS8J/Th7G5UvnO5fdLcEb431gtH+/Ouw8WxVmdu7e++neqUU5WYHOC+NcrjSkZxZQCCyyCeXfD4YY1BnHXW2xOOF0plLvkInudje++fIDnDlbv/eODS+sJZ3nh4NfzQODPZFMkjlnRvHEu1eVP+FyJeRnZhciKTUDSclZxAXzkANRqnLersvwdrTC3XwOfn/g/LZX9j189KvT39Gym6RrOPhPGdDvHQdJKnewozJSMtZU37xw3JjMBU6HbcyPkp2YTn1e4w+N7g9f3nXg3ZbWTs7zdn6Z44zXr1qc8NPDFPcGG8JdVyJJUryjVa4Svl4Sb5xkwThwtL/7+H8MGO4RS/ynnIarJqL8yR1iDv2vGw8f/xVgANo46Qo10hzVAAAAAElFTkSuQmCC
The expected response: A JSON response containing a URL to the decoded image. For example:
{ url: 'http://data-uri-to-img-url.herokuapp.com/507T4tQm70Q' }
When you have a custom HTML5 canvas, you can use this project to convert the DataURI (the 64 bit JS-serialized screenshot of the canvas) to a globally reachable Image URL.
For some reason you've 64-bit encoded an HTML5 canvas rendering of President Obama giving a speech, using Javascript:
var img_uri= canvas.toDataURL("image/png");
Yes, you can render this as an IMG tag within the same app. But how would you, say, share it on Facebook? You'd need to convert it to a URL first:
# Make a POST request to 'http://data-uri-to-img-url.herokuapp.com/images.json' with param 'image[data_uri]' set to the above DataURI input.
# This could be from an HTML form with a textarea, or programmatically using an AJAX POST request.
The result:
{ url: 'http://data-uri-to-img-url.herokuapp.com/507T4tQm70Q' }
See example.js.html for source code rendering a canvas in real-time to an image URL.
MIT License. Use with credit and care.