ImageGenerator/public/montage.php

31 lines
1.0 KiB
PHP
Raw Permalink Normal View History

2019-11-22 22:02:46 +00:00
<?php
$img = $_POST['img'];
$horizontal = intval( $_POST['horizontal'] );
$vertical = intval( $_POST['vertical'] );
$bgImage = basename( $_POST['bgImage'], ".jpg");
$landscape = intval( $_POST['landscape'] );
function panic( $msg ){
2019-11-22 22:28:46 +00:00
header("HTTP/1.1 500 Internal Server Error");
die( $msg );
2019-11-22 22:02:46 +00:00
}
if (strpos($img, 'data:image/png;base64') === 0) {
2019-11-22 22:28:46 +00:00
$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");
}
2019-11-22 22:02:46 +00:00
}else{
2019-11-22 22:28:46 +00:00
panic("Not a valid image");
2019-11-22 22:02:46 +00:00
}
$output = $return_code = NULL;
2019-11-22 22:41:40 +00:00
exec( __DIR__."/../page_generator.sh ".escapeshellarg($file)." ".escapeshellarg($horizontal)." ".escapeshellarg($vertical)." ".escapeshellarg($landscape) , $output, $return_code);
2019-11-22 22:02:46 +00:00
if( 0 === $return_code ){
$pdf = basename(implode("", $output));
2019-11-22 22:28:46 +00:00
echo( "https://2020.hackersfest.org/ImageGenerator/a4/".urlencode($pdf) );
2019-11-22 22:02:46 +00:00
}else{
panic( implode(" / ", $output ) );
}