PHP Matplotlib

<?php
header("Content-type: image/png");

$descriptorspec = array(
   0 => array("pipe", "r"),
   1 => array("pipe", "w"),
   2 => array("file", "error-output.txt", "a"),
);

$process = proc_open('python', $descriptorspec, $pipes);

if (is_resource($process)) {
    fwrite($pipes[0], "
import sys
import matplotlib
import matplotlib.pyplot as plt

plt.plot([1, 2, 5])
plt.savefig(sys.stdout.buffer)
");
    fclose($pipes[0]);

    echo stream_get_contents($pipes[1]);
    fclose($pipes[1]);

proc_close($process);
}

Komentar

Postingan Populer