ImageGenerator/public/montage.php
2019-11-22 23:03:19 +01:00

34 lines
985 B
PHP

<?php
$img = $_POST['img'];
$horizontal = intval( $_POST['horizontal'] );
$vertical = intval( $_POST['vertical'] );
$bgImage = basename( $_POST['bgImage'], ".jpg");
$landscape = intval( $_POST['landscape'] );
function panic( $msg ){
header("HTTP/1.1 500 Internal Server Error");
die( $msg );
}
if (strpos($img, 'data:image/png;base64') === 0) {
$img = str_replace('data:image/png;base64,', '', $img);
$img = str_replace(' ', '+', $img);
$data = base64_decode($img);
$file = __DIR__.'/../a4/'.microtime(true).'_'.$bgImage.".png";
if ( ! file_put_contents($file, $data)) {
panic("Failed to save canvas");
}
}else{
panic("Not a valid image");
}
$output = $return_code = NULL;
exec( __DIR__."/../page_generator.sh $file $horizontal $vertical $landscape" , $output, $return_code);
if( 0 === $return_code ){
$pdf = basename(implode("", $output));
echo( "https://2020.hackersfest.org//ImageGenerator/a4/".urlencode($pdf) );
}else{
panic( implode(" / ", $output ) );
}