1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?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";
-
- //check if file exists if so, create file with other name and return as json
- if(file_exists($filename)) {
- $asocarray[$counter]["old"] = $filename;
- $filename = $savelocation . "zwischen" . $counter . ".jpg";
- $asocarray[$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);
- ?>
|