Skip to content

code-wall/code2image

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

code 2 image api

This API allows you to get a syntax highlighted image representation of your code.

GET /image

Parameters

Name Type Description
code string

Code snippet encoded as a JSON string. Only specify either code or id, not both.

id string

An id of a codebin.it snippet. Only specify either code or id, not both.

language string

Language for which the syntax highlighting will be used.

twitterFriendly string

Whether the image should be cropped and resized to fit nicely as a twitter summary card https://dev.twitter.com/cards/types/summary-large-image

facebookFriendly string

Whether the image should be cropped and resized to fit nicely as a facebook open graph image

Examples

HTML:

<img src='http://api.codebin.it/image?code="function() {\n\tconsole.log(\"hello world\");\n};"'/>

Javascript:

var myImage = document.getElementById('my-image');
var code = 'function() {\n\tconsole.log("hello world");\n};';
var url = 'http://api.codebin.it/image?code=' + JSON.stringify(code);
fetch(url).then(function(response) {
    return response.blob();
}).then(function(response) {
    var objectURL = URL.createObjectURL(response);
    myImage.src = objectURL;
});

cURL:

curl -G "http://api.codebin.it/image" \
     --data-urlencode "code=\"function() {\\n\\tconstole.log(\\\"hello world\\\");\\n}\"" \
     -o mycode.png

About

An API to generate formatted PNG image of a snippet of code

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published