(see comments on response by Hodorogea)
I found two ways of handling it. One in the Route itself since I use a single function call to handle the response and don't need a lot of sanitizing of input.
// example right in the routing including a color parameter
Route::get('/colorsvg/{color}/{filename}', function($color,$filename) {
// remove any .svg suffix on the text
$custom = preg_replace('/\.svg$/i', '', $filename);
// add # on the front of numeric RGB values if needed
if(preg_match('/^[a-fA-F\d]{6}$/', $color)) $color = '#' . $color;
// function returns array with width, height and svgdata
$svg = SDKapi::getCustomTextAsSvg($custom, $color);
return response($svg['svgdata'], 200)
->header('Content-Type','image/svg+xml');
});
or using a simple controller method (no color in this one)
api.php in routes:
Route::get('/customsvg/{filename}', [SVGController::class, 'customsvg']);
SVGController.php
public function customsvg(Request $request, $filename)
{
$custom = preg_replace('/\.svg$/i', '', $filename);
$svg = SDKapi::getCustomTextAsSvg($custom);
return response($svg['svgdata'], 200)
->header('Content-Type', 'image/svg+xml');;
}
