geometria(); if ($geometry === null) { throw new RuntimeException('La geometria salvata per questo territorio non รจ leggibile: ridisegna il poligono.'); } $response = Http::timeout((int) config('piantine.renderer_timeout')) ->post(rtrim((string) config('piantine.renderer_url'), '/') . '/render', [ 'geometry' => $geometry, 'marginRatio' => (float) config('piantine.margin_ratio'), 'maxSide' => (int) config('piantine.max_side'), ]); if (! $response->successful()) { $dettaglio = $response->json('error') ?? ('HTTP ' . $response->status()); throw new RuntimeException('Il renderer delle mappe ha risposto con un errore: ' . $dettaglio); } $png = $response->body(); if ($png === '' || ! str_starts_with($png, "\x89PNG")) { throw new RuntimeException('Il renderer delle mappe non ha restituito un PNG valido.'); } $path = 'territori-mappe/territorio-' . $mappa->territorio_id . '.png'; Storage::disk('public')->put($path, $png); $mappa->update([ 'image_path' => $path, 'rendered_at' => now(), ]); return $path; } }