Compilers
Graphical output

The following document provides information on:

  • how the user's program should be saving images and how to download graphical data,
  • how the images can be generated by the user's program.

Saving graphics

To obtain graphical result, the user's program should return it to the standard stream of output data (stdout). This enables downloading output data of the submission, e.g., by the use of API (for example Sphere Engine Compilers module).

Note: The Sphere Engine Compilers Widget recognizes graphical output data and displays it as image, automatically.

Examples showing how to generate images can be found further in the document.

Alternative mechanism

In some programming languages it's a common approach to generate image files during the program execution (e.g., R and Octave).

For these programming languages, Sphere Engine offers an alternative mechanism of producing the graphical output: when an image file is detected, it is this file that is treated as output instead of the standard output stream (stdout).

During program execution, the file should be saved using an appropriate name and extension. The table below shows a list of supported programming languages and the required names of the output files.

ID Language name Output file name
117 R out.png
127 Octave out.png

Sample usages of the mechanism are presented further in the document.

Additional libraries

If you need any image generating library for any language, please let us know, and we'll make it happen.

Examples

import matplotlib.pyplot as plt
import sys
plt.plot([1, 2, 3, 4])
plt.ylabel('some numbers')
plt.savefig(sys.stdout.buffer, format='png')
from PIL import Image
import sys

img = Image.new('RGB', (60, 30), color = 'red')
img.save(sys.stdout.buffer, format='PNG')
bitmap(file="out.png", type = "png256", height = 6, width=6, res=72)
cars <- c(1, 3, 6, 4, 9)
plot(cars)
x = [1 2 3 4 5 6 7 8 9 10];
y1 = [.16 .08 .04 .02 .013 .007 .004 .002 .001 .0008 ];
y2 = [.16 .07 .03 .01 .008 .003 .0008 .0003 .00007 .00002 ];

semilogy(x,y1,'-bo;y1;',x,y2,'-kx;y2;');
title('Plot title');
xlabel('X Axis');
ylabel('Y Axis');

print out.png
<?php

$imageBase64 = 'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAB20lEQVQ4jc2RPWiTURiFn/f7uaZpbBNLQ0RRJ0Ho5NZVyCJSSOi1tZOg4j/qIm7i4CCIm0gGBxFKSnCoODhVKE66qUuLi4hLU5uvCUXz/dzr8MU2se56lss9HM55z/vCf4Oh6veD6I3Rfi4z2zqC7ozvMFYyeuMQWPnNOAC+Ds4lrvPVR1bVdKCz1eZ+NR3cNwmfFfHqnpn2UQClg2cG+aJOb84PGAic6L1FEfs4dv2niL0FuEDe2GQyTZVyOogtc9c62wYY80DgLfDKj72JsJE/aR0mLSwBi1HIIogFrqecXOWemF7oIDLV1mHjygUcUw8X9n0CGNLrBxK8yxZ5GTVG3/Xrdxko3foITAARIg8xBIi9AxSAH2GmO87z0tbADv7AjqnFiGMjgWRb/1N5/eKBD4AkMmU9zpOYevii8AEgW23WY8+7aMW8ZmFsc1dartIphl78BGvjUDmXmM+3mGruVcqvIXZYcG93GyMrzAUFFZmaRQoO7rVuY2TFA4jceA6oIoIfshRBzc/4s1h7Jm2SlJUO3hBxHKSUdjQ3gCsOgHFlGWgDgbjxctrfvgei3qCPQtyzwE1gC4h7J+6DXstx6lt2gKu0x9TM+rF+KlfpFIf1Wukvy/9H+AX8wK0WBAVeRAAAAABJRU5ErkJggg==';
$image = base64_decode($imageBase64);

echo $image;