config = new licenseplaterecognizer_c(); } /** * @inheritDoc */ public function requireModuleEnabled(): void { if (!(bool)$this->config->enabled->getVariableValue()) { throw new Exception('licenseplaterecognizer module is not enabled.'); } } /** * @inheritDoc * @throws Exception If the module is not enabled or if there is an error in the API request * @throws Exception If the API response cannot be parsed */ public function licenseplaterecognizer(string $base64_image): array { $image_processor = new image_processor(); //ADD PARAMETER IN REQUEST LIKE regions $data = array( 'upload' => $base64_image, 'regions' => 'us-ca' // Optional ); // Prepare new cURL resource $ch = curl_init('https://api.platerecognizer.com/v1/plate-reader/'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLINFO_HEADER_OUT, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_2TLS); // Set HTTP Header for POST request curl_setopt($ch, CURLOPT_HTTPHEADER, array( "Authorization: Token " . $this->config->api_key->getVariableValue() ) ); // Submit the POST request and close cURL session handle $result = curl_exec($ch); curl_close($ch); $response_data = json_decode($result, true); if (isset($response_data['results']) && count($response_data['results']) > 0) { return [ 'success' => true, 'license_plate_number' => $response_data['results'][0]['plate'] ?? null, 'confidence' => $response_data['results'][0]['score'] ?? null, 'raw_response' => $response_data, ]; } else { return [ 'success' => false, 'message' => 'No license plate detected.', 'raw_response' => $response_data, ]; } } }