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); ?>