12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- ini_set('display_errors', 1);
- ini_set('display_startup_errors', 1);
- error_reporting(E_ALL);
- header('Content-Type: application/json');
-
-
- $imgurl = htmlspecialchars($_POST["url"]);
- $alldata = json_decode($_POST["alldata"]);
- //var_dump( $alldata->rects );
- $savelocation = $_POST["savelocation"];
- //echo $savelocation;
-
- $asocarray = array();
- if ( ! is_writable($savelocation)) {
- $asocarray["error"] = $savelocation . ' must be writable!!!';
- echo json_encode($asocarray);
- exit();
- }
-
- else{
- $im = imagecreatefromjpeg($imgurl);
- $counter = 0;
- foreach($alldata->rects as $rect){
- $filename = $savelocation;
-
- $filename = $filename . $alldata->name . "_";
- $filenamecpy = $filename;
-
- foreach($rect->pattern as $key => $val) {
- $filename = $filename . $key . ";" . $val . "_";
- }
- if($rect->idtext != ""){
- $filename = $filename . "ID" . ";" . $rect->idtext . "_";
- }
-
- //only save image if at least one checkbox is active or a text is set.
- if($filenamecpy != $filename){
-
- $filename = substr($filename, 0, -1);
- $filename = $filename . ".jpg";
-
- $asocarray["url"][$counter] = $filename;
-
- //check if file exists if so, create file with other name and return as json
- if(file_exists($filename)) {
- $asocarray["override"][$counter]["old"] = $filename;
- $filename = $savelocation . "zwischen" . $counter . ".jpg";
- $asocarray["override"][$counter]["new"] = $filename;
- }
-
- //echo $filename;
- $im2 = imagecrop($im, ['x' => $rect->X, 'y' => $rect->Y, 'width' => $rect->W, 'height' => $rect->H]);
- imagejpeg($im2, $filename);
- imagedestroy($im2);
- }
- ++$counter;
- }
- }
- echo json_encode($asocarray);
- ?>
|